Table of Content
Table of Contents | ||||||||
---|---|---|---|---|---|---|---|---|
|
...
A DateTime object represents a specific instant of time. It must be a Coordinated Universal Time (UTC) or the time zone must be indicated by the offset to UTC. In other words, the time must be unique in all time zones around the world.
The XJDF DateTime object provides different constructors for initializing. The default constructor creates the current date as XJDF DateTime object whereas the custom constructors initialize the object by a custom value.
Code Block | ||
---|---|---|
| ||
// current time DateTime d1 = new DateTime(); System.out.println(d1.toString()); // 2013-02-24T18:34:01+01:0001Z // specify date only DateTime d2 = new DateTime(2013, 02, 24); System.out.println(d2.toString()); // 2013-02-24T2324T00:59:00+01:0000Z // specify date and time DateTime d3 = new DateTime(2013, 02, 24, 15, 30); System.out.println(d3.toString()); // 2013-02-24T15:30:00+01:0000Z // specify date as string DateTime d4 = new DateTime("2013-02-24T18:30:00+00:0000Z"); System.out.println(d4.toString()); // 2013-02-24T18:30:00Z // initialize DateTime from CalendarDate DateTime d5 = new DateTime(new GregorianCalendarDate()); System.out.println(d5.toString()); // 2013-02-24T18:42:46+01:00:46Z |
Creating instances of DateTime with time zone offset works at the moment but should be avoided.
The preferred date pattern is yyyy-MM-dd'T'HH:mm:ss'Z'
Internally the XJDF DateTime object holds the information as Calendar. This object can also be accessed using the Getter-Method.
Note: The getCalendar() returns a exact copy of the Calendar used in DateTime. This prevents users from (accidently) changing the actual date.
Code Block | ||
---|---|---|
| ||
// read DateTime DateTime dateTime = new DateTime(); dateTime.getCalendar() |
...