Can anybody tell about three things:
- How to retrieve TimeZone from java.util.Date instance?
- How to know whether Daylight savings is applicable?
I suppose I can know it by doing timeZone.getDSTSavings, but problem I am facing is that even if I make my system’s date as Feb 1 2012, still I am getting the value as positive (I guess 3600000) - How to convert EST time to EDT or vice versa?
There’s no such thing. A
Datejust represents a number of milliseconds since the Unix epoch, which was midnight on January 1st 1970 UTC. It’s not associated with a particular calendar system or time zone. To put it another way, if a friend and I are on the phone together (with a zero latency 😉 and I click my fingers, we would both agree on theDateat which that click too place – even if I’m using the Gregorian calendar and he’s using the Julian calendar, and even if I’m in London and he’s in New York. It’s the same instant in time.Ideally, use Joda Time instead of
java.util.Date/Calendar/TimeZone, but withinTimeZoneyou can useTimeZone.getOffset(long)to find the offset from UTC, orTimeZone.inDaylightTime(Date)to just give you a yes/no answer.Usually that’s an invalid question – because at any one instance in time, either EST or EDT applies. You normally convert from one time zone to another, and “EDT” and “EST” aren’t different time zones – they’re different offsets within the same time zone. The fact that you’re asking for this suggests that you may be modelling your data incorrectly to start with (which is unfortunately easy to do with date/time values). Please give us more information and we may be able to help you more.