Reputation: 219
I am getting different value for TimeZone.getDefault().getID() on different systems. For example, in case of Indian standard time, On one of the system we are getting "GMT+5:30": while on another we are getting "Asia/Calcutta". We are expected to get "Asia/calcutta" strings on all machines.
Why is there an inconsistency for such behavior?
Is there any way to get consistent behavior across different systems windows/MAC?
What is the best way to get client time zone programmatically using Java?
Upvotes: 2
Views: 2085
Reputation: 1563
In case someone has the same problem on Linux and can't find an answer:
UTC
CET
)UTC
The problem could be:
/etc/localtime -> /usr/share/zoneinfo/Europe/Paris
/usr/share/zoneinfo/Europe/Paris
contains UTC
informationThe cause for this could have been a simple cp /usr/share/zoneinfo/UTC /etc/localtime
replacing the contents of /usr/share/zoneinfo/Europe/Paris
instead of overwriting /etc/localtime
which was a symlink instead of a file!
Upvotes: 0
Reputation: 1500515
It sounds like the two machines are configured differently - it's as simple as that. For example, if your first system is Windows you may have unticked the box saying "Automatically adjust for Daylight Saving Time".
If you know you need Asia/Calcutta for all systems, then use that explicitly. I try to avoid using the default time zone wherever possible, to be honest. Even when I do use it, I try to use it explicitly so that it's obvious from the code that I'm trying to use the system time zone, rather than it just being accidental.
Upvotes: 3