datetime - How to handle daylight saving time properly in Java 7 without Joda Time? -


before marking duplicate read thoroughly plus can't use joda time , java 8 time.util*.

i'm trying current date of country dst enabled. since time zone [local-millis] = [utc-millis] + [offset-millis] added dst_offset time in dst enabled country, done on linux machine gmt_time + local_time_zone_offset + dst_offset current local time.

the code print current time of istanbul has dst enabled 1 hour.

public class dstinstanbul {      public static void main(string...args){          calendar calendar = calendar.getinstance();          timezone timezone = timezone.gettimezone("europe/istanbul");          calendar.settimezone(timezone);          calendar.add(calendar.millisecond, timezone.getdstsavings());           simpledateformat simpledateformatlocal = new simpledateformat("yyyy-mm-dd hh:mm:ss");         simpledateformatlocal.settimezone(timezone.gettimezone("europe/istanbul"));          system.out.println("current date , time : " + simpledateformatlocal.format(calendar.gettime()));          system.out.println("current date , time : " + simpledateformatlocal.format(calendar.gettime()));        system.out.println("the timezone : " + calendar.gettimezone().getid());      } } 

which gave me correct output

current date , time : 2015-11-01 20:49:54 hour of day : 20 timezone : europe/istanbul 

but since above code not of generic tried add following line, if daylight enabled add dstsaving changed following calendar.add(calendar.millisecond, timezone.getdstsavings()); with

if (timezone.indaylighttime(new date())){             calendar.add(calendar.millisecond, timezone.getdstsavings());        } 

but problem if output without dst. , printing system.out.println(timezone.indaylighttime(new date())); gives me false , hence result daylight saving there can see in link istanbul clock

current date , time : 2015-11-01 19:54:49 timezone : europe/istanbul. 

the same logic time zone brazil gives me true indaylighttime displays result 1 hour ahead now

ideone link code ordered in way discussed 1. https://ideone.com/4nr5ym 2.https://ideone.com/xh7vhp 3.https://ideone.com/tqenb5

my question problem timezone.indaylighttime(new date()) istanbul time zone. why it's showing false. why brazil i'm not getting current dst time when indaylighttime true. proper way handle such situation ?

there seems few questions time zones , daylight savings in turkey today.

this because turkey has changed date daylight savings switch november 1 november 8.

the timezone data in jvm may not current change. oracle has update jvm.

the timezone data updater download link above executable jar file. update jvm on unix host:

sudo java -jar tzupdater.jar --update --location http://www.iana.org/time-zones/repository/tzdata-latest.tar.gz 

the tool doesn't seem output on updates, verify run:

java -jar tzupdater.jar --version  

the version of timezone data turkey update tzdata2015g


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -