EDIT: OK. I unfortunately have to admit my understanding of Java time was crucially flawed, making this question meaningless. I always thought that System.currentTimeMillis() returned the local time. Why? Because when you create a Date with it, it just contains that, and no reference to a timezone, but still prints out the local time when passed to System.out.println(). It never crossed my mind that it was toString() that converted the (UTC) time to then local time zone. :(
I want to create a client-server application in Java. Time plays an important role. So I decided to standardize on GMT/UTC for the time. I also know from experience that many user's PC have the totally wrong time and/or timezone. Finally, I would like to have more precise time then milliseconds.
So I created a class that connects to the Internet at start, and computes the offset to UTC, independently of what the local time and timezone is. In other words, I have a static Java method that returns the UTC time in nanoseconds, and works on any PC independently of the local time settings.
Now, my problem is that I wanted to use JSR 310 to manipulate the time (actually the Java 7 backport), and I fail to see how to define a clock which is not based on the local time.
It seems to me that the methods Clock.millis() and Clock.instant() have to use the local time for things to work correctly [EDIT: Because those methods blindly return System.currentTimeMillis(), independent of the set time zone attribute]. So I basically have to turn my UTC time to local time, to create an Instant, just so I can then create a UTC ZonedDateTime that will convert the local time back to UTC again. This is just insane. If I use the UTC time in Clock.millis() and Clock.instant(), and then create a UTC ZonedDateTime , the local time offset, which I don't want to have anything to do with, gets applied twice.
Converting from UTC to local and back again is expensive, and so I would really like to be able to use purely UTC. I'm working on a real-time game, rather then a web-app, where such small delays would be meaningless.
I could just return the UTC time, and "pretend" the timezone is "local" to get the correct numbers, but things would probably break at DST boundaries, and it would make converting the time to some other timezone much more complicated.