Reputation: 357
EST time conversion with daylight saving time it is coming wrongly
private void timeConversion() {
String s = "2016-08-29 1:40:00 AM";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a", Locale.ENGLISH);
df.setTimeZone(TimeZone.getTimeZone("EST"));
Date timestamp = null;
try {
timestamp = df.parse(s);
df.setTimeZone(TimeZone.getDefault());
System.out.println(df.format(timestamp));
} catch (ParseException e) {
e.printStackTrace();
}
}
Upvotes: 1
Views: 1116
Reputation: 10964
The time zone EST does not respect any daylight saving time offsets:
TimeZone estTz = TimeZone.getTimeZone("EST");
System.out.println(estTz.useDaylightTime()); // prints 'false'
That is the time zone EST will always have a -5:00 hour offset to UTC.
This is probably due to some locations in Canada, Mexiko and Central America (Panama) not using DST but using EST all the year.
If you want a time zone with DST offset, you should use something like US/Eastern or America/New_York, etc:
TimeZone usEasternTz = TimeZone.getTimeZone("US/Eastern");
System.out.println(usEasternTz.useDaylightTime()); // prints 'true'
Upvotes: 1