Current time in java with summer savings

I stumbled upon this piece of code to get the current time in EST with daylight saving time. It seems to work fine when it is checked on the Internet by the time displayed on sites providing current time in EST with daylight saving time.

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss.SSS"); dateFormat.setTimeZone(TimeZone.getTimeZone("EST5EDT")); System.out.println(dateFormat.format(new Date())); 

I just want to confirm, has anyone used something like this before, or is there a better way to achieve the same. I cannot use the Joda library due to limitations.

Thanks in advance.

+6
java date time
source share
1 answer

Yes, this is the best (and really only) way to do this using standard Java libraries.

+1
source share

All Articles