java - Return BST/GMT for a given date -
in java accepted method determining daylight savings time given date object locale.
for example if had 2 date objects
date date = new date("01/01/2014"); date date2 = new date("01/07/2014");
and locale "europe/london", 'date' should return gmt , date2 should return "bst"
string timezone = new string("europe/london"); timezone tz = timezone.gettimezone(timezone); system.out.println(tz.getdisplayname(tz.indaylighttime(date), timezone.short)); timezone tz2 = timezone.gettimezone(timezone); system.out.println(tz2.getdisplayname(tz2.indaylighttime(date2), timezone.short));
both these examples print gmt, shouldn't second print bst?
i think dates both not in daylight saving time, pattern mm/dd/yyyy, dates 1st jan 2014 , 7th jan 2014. way: constructor use deprecated!
date date = new date("01/01/2014"); date date2 = new date("01/07/2014"); date date3 = new date("07/07/2014"); calendar cal = calendar.getinstance(locale.uk); cal.settime(date); system.out.println(date + " " + cal.gettimezone().indaylighttime(date)); cal.settime(date2); system.out.println(date2 + " " + cal.gettimezone().indaylighttime(date2)); cal.settime(date3); system.out.println(date3 + " " + cal.gettimezone().indaylighttime(date3));
this should give hint. @ least know if date in daylight saving time, how time called second problem, don't think it's resolveable standard-api. have tried looking @ http://www.joda.org/joda-time/? it's api datetime calculations.
Comments
Post a Comment