public class DateTime extends Object
This object serves as a DTO both inside XML and in URLs (usually as
a query parameter, but it may be used inside a path, too). For this
purpose, its toString() method and its single-String-argument-constructor
are used.
| Constructor and Description |
|---|
DateTime(Date date)
Creates a new instance from the given
date. |
DateTime(String dateString)
Creates a new instance from the given ISO-8601-encoded
dateString. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
long |
getMillis()
Gets the number of milliseconds since 1970 January 1 00:00:00 GMT represented by this
DateTime object. |
int |
hashCode() |
Date |
toDate()
Converts this
DateTime into a new Date instance. |
String |
toString()
Returns an ISO-8601-encoded timestamp which can be passed to
DateTime(String). |
public DateTime(String dateString)
dateString.
The result of the toString() method can be passed to this constructor
to obtain a copy of the original DateTime instance. This feature should
be used to transport ISO-8601-encoded timestamps over the network:
DateTime original = new DateTime(new Date()); String iso8601encoded = original.toString(); // iso8601encoded could now be transported to a remote machine as part of a // REST URL (e.g. as query parameter). // The remote machine might then decode it using this REST-conform constructor: DateTime copy = new DateTime(iso8601encoded);
Because of this constructor, DateTime parameters can be directly used in
REST resource (a.k.a. service) methods.
dateString - the ISO-8601-encoded form of a timestamp. Must not be null.toString()public DateTime(Date date)
date.
Because Date instances are mutable, the given date is cloned.
This way it can be guaranteed that DateTime instances are immutable.
date - the date to be cloned and wrapped in the new DateTime instance. Must not be null.public long getMillis()
DateTime object.DateTime object.Date.getTime()public String toString()
toString in class ObjectDateTime(String)Copyright © 2013-2014. All Rights Reserved.