Daylight saving time DST (daylight saving time) in Java for daylight saving time "turn"

Source: Internet
Author: User

In 1916, Germany first introduced daylight saving time, the UK because of fear of Germany will get greater benefits, so closely followed also took daylight

From 1986 to 1991, the People's Republic of China practiced daylight saving time for six years nationwide.

サマータイム Summer (Japan does not have daylight saving time, but it has been stationed in the United States for 1948 years? 1951)

A bit of content source: http://blog.csdn.net/java2000_net/article/details/4362316

==========================================================================================

Articles from the forum: http://topic.csdn.net/u/20090711/01/82c73f46-20ac-4a95-977d-f3f077ce822a.html

The Java code as below

[Java] view Plaincopy 
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:SS");  String stime = "1991-04-07 00:00:00";  Date time = Sdf.parse (stime);  Calendar cd = Calendar.getinstance ();  Cd.settime (time);  Cd.add (Calendar.date, 7);  Time = Cd.gettime ();  System.out.println (Sdf.format (time));  

  

After running, did not get the expected

1991-04-14 00:00:00

But

1991-04-14 01:00:00

1 hours more out of thin air.

According to the research results of dragon fruit, this is daylight saving time Oh, using Calendar.dst_offset can get offset.

Daylight saving time is implemented by TimeZone subclass Sun.util.calendar.ZoneInfo.

The data in the zoneinfo is stored in the%jre_home%/lib/zi directory. (Note that it is in the directory of the JRE)

Our machine generally uses the time zone name Asia/shanghai, the corresponding time zone information file is located:

In%jre_home%/lib/zi/asia/shanghai, this is a binary file.

By Sun.util.calendar.ZoneInfoFile resolution, you can get the time required to take daylight savings:

1940-06-03 01:00:00 ~ 1940-09-30 23:00:00
1941-03-16 01:00:00 ~ 1941-09-30 23:00:00
1986-05-04 01:00:00 ~ 1986-09-13 23:00:00
1987-04-12 01:00:00 ~ 1987-09-12 23:00:00
1988-04-10 01:00:00 ~ 1988-09-10 23:00:00
1989-04-16 01:00:00 ~ 1989-09-16 23:00:00
1990-04-15 01:00:00 ~ 1990-09-15 23:00:00
1991-04-14 01:00:00 ~ 1991-09-14 23:00:00

The previous paragraph indicates the start of the day, meaning that 0 points of that day are absent in that time zone.

The latter segment represents the end of the day, and this time calculation is complex:

If the current time is: 1986-09-13 23:00:00, add 1 hours to 1986-09-14 00:00:00
If the current time is: 1986-09-13 22:00:00, add 2 hours to 1986-09-13 23:00:00, since 1986-09-13 23:00:00 is daylight saving time, the clock needs to be dialed back.

The daylight saving time algorithm in a programming language is very complex because daylight savings are different in each timezone.

============================================================================================

Extension: GMT

Greenwich Mean Time GMT

Ext.: http://blog.csdn.net/sxzlc/article/details/7281603

Daylight saving time DST (daylight saving time) in Java for daylight saving time "turn"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.