Pranav Raulkar wrote:Thanks Jeff, very brisk reply.
You're very welcome.
I was aware of certain TZ not being into exsistence
Most of the rules in common use in the world are probably present. It's just that they might not be accessible by their "common" names that we're familiar with, like "MST", primarily because the same short name might refer to different TZs in different regions of the world.
One question again, can this be done using timezone offset? How does the timezone offset work?
I've never used it, but I suppose you could. The docs for getOffset() say it returns, "the amount of time in milliseconds to add to UTC to get local time", so I suppose if you want to know the difference between to TZs at some instant, you could subtract their getOffset() results. Note, however, that you do NOT want to then add that offset to a Date, thinking that will "convert" the Date from one TZ to another.
A Date object does not have any TZ associated with it. (Another view is that it always has GMT associated with it, but that line of thinking leads to confusion and mistakes, I've found.)
If you are in Denver and I am in LA and we have a friend in London and another in Tokyo, and, at the same instant, we all execute System.currentTimeMillis(), or new Date(), we will all get the exact same result for the long millis-since-epoch value, regardless of our TZs, and regardless of any DST that may or may not be in effect. TZ only comes into play when we format the Date for display. None of the code in my example changed the Date object in any way. The all just said, "Oh, the time is X millis since the epoch? Okay, well, that means that that instant in time is Y if you're in Dever and Z if you're in LA."
I have never found a reason to use the offset from
Java's TZ class. That's not to say that you won't, but DON'T use it to adjust the millis of a Date object.