读书人

Joda-time 施用

发布时间: 2012-10-25 10:58:57 作者: rapoo

Joda-time 使用

JDK Interoperability

The?DateTime?class has a constructor which takes an?Object?as input. In particular this constructor can be passed a JDK?Date, JDK?Calendar?or JDK?GregorianCalendar?(It also accepts an ISO8601 formatted String, or?Long?object representing milliseconds). This is one half of the interoperability with the JDK. The other half of interoperability with JDK is provided by?DateTime?methods which return JDK objects.

Thus inter-conversion between Joda?DateTime?and JDK?Date?can be performed as follows

    // get current moment in default time zone    DateTime dt = new DateTime();    // find the moment when London will have / had the same time    dtLondonSameTime = dt.withZoneRetainFields(DateTimeZone.forID("Europe/London"));

A set of all TimeZone ID strings (such as "Europe/London") may be obtained by calling?DateTimeZone.getAvailableIDs(). A full list of available time zones is provided?here.

?

?

读书人网 >编程

热点推荐