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
时间: 2024-12-31 03:10:04

Date Time Calendar的相关文章

Java日期与时间的处理/Date,String,Calendar转换

public class Demo01 { //Java中Date类和Calendar简介 public static void main(String[] args) { long now=System.currentTimeMillis(); System.out.println("now= "+now); Date d1=new Date(now); System.out.println("d1= "+d1); Calendar c1=Calendar.get

java 日期操作,Date、Calendar 操作

java开发中避免不了日期相关操作,这里总结了一些常用方法~ 直接上码: package jse; import java.io.UnsupportedEncodingException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; /**  * 常用日期操

java Date和Calendar类

最近在无聊的看书,遇到一编程题目,问题描述如下: 黑色星期五源于西方迷信:耶稣基督死于星期五,而13也是一个不吉利的数字.黑色星期五即该日同时是星期五又是13号,求未来几年内这样的日子. 基于该问题会涉及到java中的关于时间类的部分,故尝试通过该题目总结现阶段的java Date和calendar类的问题. 一.Date类 查阅API文档可知,Date类源于jdk1.0版本,并在jdk1.1版本中其绝大多数方法被Calendar类中方法所代替.Date类构造函数public且未abstrct,

Freebie: Date Picker Calendar Demo Form For Oracle Forms 6i

I have already posted and provided the required PLSQL Library and the Calendar FMX file in my previous blog post Date Picker Calendar For Oracle Forms but some people were still not able to use this utility in their forms, so I thought to provide a d

Date Picker Calendar For Oracle Forms 6i

Giving date picker calendar option to user for date type fields in Oracle Forms. I am providing you the form (FoxCal.Fmx) and two libraries (General.plx and Calendar.pll). You can download these files by clicking below link: Download Form and require

java中Date与Calendar详解

在开发中,Date与Calendar使用率上是相当高的,如果对它们不太了解,那么,在实际开发中会发生各种状态.如:为什么我获得到的本月的月份不是本月等等. Date篇 public class Dateextends Objectimplements Serializable, Cloneable, Comparable<Date>类 Date 表示特定的瞬间,精确到毫秒 在类 Date 所有可以接受或返回年.月.日期.小时.分钟和秒值的方法中,将使用下面的表示形式: 年份 y 由整数 y -

Java中的Date和Calendar的常用用法

在java中用到的最多的时间类莫过于 java.util.Date了,由于Date类中将getYear(),getMonth()等获取年.月.日的方法都废弃了,所以要借助于Calendar来获取年.月.日.周等比较常用的日期格式 注意:以下代码均已在jdk1.6中测试通过,其他版本可能使用不同,请注意! Date与String的相互转换 /**  * Date与String的互转用法,这里需要用到SimpleDateFormat */Date currentTime = new Date();

java日期类型转换总结date timestamp calendar string

用Timestamp来记录日期时间还是很方便的,但有时候显示的时候是不需要小数位后面的毫秒的,这样就需要在转换为String时重新定义格式. Timestamp转化为String: SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义格式,不显示毫秒 Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时间 String

Date和Calendar知识

文章来源:http://www.cnblogs.com/manue1/p/4495983.html Java中的日期操作 Date : getTime() .setTime() SimpleDateFormate :   Formate(Date). parse(String s) Calendar : getInstance().set() .get().getActualMaximum().add().  gettime().setTime(Date). 字符串.Date.Calendar之

时间日期处理date,Calendar类

1.         Date类(该类现在很少用了) l         Date类对象的创建: n         创建一个当前时间 //默认是创建一个代表系统当前日期的Date对象 Date d = new Date(); n         创建一个我们指定的时间的Date对象: 下面是使用带参数的构造方法,可以构造指定日期的Date类对象,Date类中年份的参数应该是实际需要代表的年份减去1900,实际需要代表的月份减去1以后的值. //创建一个代表2009年6月12号的Date对象 D