Date Time Calendar

  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

转载于:https://www.cnblogs.com/wade-case/p/4532081.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值