码迷,mamicode.com
首页 > 其他好文 > 详细

Date Time Calendar

时间:2015-05-27 00:58:17      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

  1. Gregorian Calendar
  2. GMT and UTC
    • GMT
      • GMT is a time zone officially used in some European and African countries. 
    • UTC
      • UTC is not a time zone, but a time standard that is the basis for civil time and time zones worldwide. This means that no country or territory officially use UTC as a local time.
  3. UTC, GMT and Daylight Saving Time
    • Neither UTC nor GMT ever change for Daylight Saving Time(DST). However, some of the contries that use GMT switch different time zones during their DST period.
    • For example, the United Kingdom is not on GMT all year, it uses British Summer Time (BST), which is one hour ahead of GMT, during the summer months. 
  4. Day Light Saving Time(DST)
    • History: http://www.timeanddate.com/time/dst/history.html
    • DST is used to save energy and make better use of daylight
    • Clocks are set ahead one hour when DST starts. This means that the sunrise and sunset will be one hour later, on the clock, than the day before
  5. Date Time in Java
    • standard before JDK1.8: java.util.Date represents a specific moment in time
    • Joda Time
      • The primary class used to represent an instant in time is the org.joda.time.DateTime. A DateTime, as it name implies, encodes both the date and the time. It also includes time zone information so that it knows how to interpret it in terms of hours and minutes. This object is immutable, which means it is thread-safe. It also means that when you perform "date math" on that object, you get a brand new DateTime as a result.
      • Joda Time lets you use the intuitive numbers for months, with 1 meaning January and 12 December
      • Joda Time has another class you may want to use to represent a particular date and time, LocalDateTime. It is very similar to the DateTime, except that it does not include any time zone information
      • Durations, Periods, Intervals
        • Duration: A duration is a length of time, which Joda Time encodes as the number of milliseconds. Joda Time uses periods to do the date math on DateTime. If you specify a Period or Duration using DateTimes that cross a DST change, or from different time zones, it does "the right thing"
        • DateTime beforeDST = new DateTime(2015, 3, 10, 1, 45);
          DateTime afterDST = new DateTime(2015, 3, 10, 3, 45);
          Period period = new Period(beforeDST, afterDST);
          System.out.println("#Hours between 1:45 and 3:45: " + period.getHours());
          // #Hours between 1:45 and 3:45: 1
        • Interval: represents a specific span of mathematical intervals, closed at the start(inclusive) end at endpoint(exclusive).
        • Durations, Periods and Intervals are immutable(thread safe). Use the with*() method to get the modified values
    • When you store a DateTime, use a consistent time zone. In many cases, your best option is using UTC because it’s free of DST silliness
  6. This blog content mostly comes from Nancy Deschenes‘s Date and Time Manipulation in Java Using Joda Time
  7. end

Date Time Calendar

标签:

原文地址:http://www.cnblogs.com/wade-case/p/4532081.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!