datetime - Java convert date to EST timezone to respecting DST -


i want current date converted america/montreal timezone. i'm doing this:

date date = new date(); timezone timezone = timezone.gettimezone ("america/montreal"); calendar cal = new gregoriancalendar(timezone); cal.settime(date); string whatiwant = "" + cal.get(calendar.hour_of_day) + ':'+                     cal.get(calendar.minute)+ ':'+ cal.get(calendar.second);  log.info(whatiwant); 

the conversion fine wondering how robust code is. happen when in no daylight saving?

that code fine. java automatically takes winter time or summer time account.

you using dateformat object convert date string, setting desired time zone on dateformat object:

date date = new date();  dateformat df = new simpledateformat("hh:mm:ss");  // tell dateformat want time in timezone df.settimezone(timezone.gettimezone("america/montreal"));  string whatiwant = df.format(date); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -