Class DateTimeValue
- All Implemented Interfaces:
Serializable,Comparable<DateTimeValue>
This class represents a date or date-time value, with an optionally attached time zone.
If no time zone is attached, it is treated as a local date/datet-time value, but the internal value is normalized to UTC time zone. If only a date value is given (no time information), the time is set to midnight.
For any operation that needs a time zone, if none is specified, the UTC time zone is used. Check
with isLocal() whether a time zone is specified or not.
This class is supposed to ease creation of a UTC timestamp values. Internally the point in time is maintained as a UNIX timestamp (milliseconds offset from 1970-01-01T00:00:00Z).
This class is immutable.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDateTimeValue(long millis, @Nullable org.joda.time.DateTimeZone timezone, boolean datetime) Ctor. -
Method Summary
Modifier and TypeMethodDescriptionintstatic DateTimeValuedate(org.joda.time.LocalDate date) Creates a local date value.static DateTimeValuedate(org.joda.time.ReadableInstant datetime) static DateTimeValuedateTime(org.joda.time.LocalDateTime datetime) Creates a date-time value from the specified local-time.static DateTimeValuedateTime(org.joda.time.ReadableInstant instant) Creates a date-time value with the information supplied by the instant.booleanorg.joda.time.DateTimeReturns aDateTimeobject whose millis are set to the end of this day.org.joda.time.DateTimeReturns aDateTimeobject whose millis are set to the start of this day.longReturns the millis of this date-time value.@Nullable org.joda.time.DateTimeZoneReturns the time zone.org.joda.time.DateTimeReturns this value asDateTimewith UTC time zone.Returns the weekday of this date.inthashCode()booleanisAfter(DateTimeValue dt) Returns whether this is after the specified value.booleanReturns whether this is before the specified value.booleanisDate()Returns whether this represents a date-only value - no time information is specified.booleanReturns whether this represents a date-time value.booleanisEqual(DateTimeValue dt) Returns whether this is equal the specified value.booleanisLocal()Returns whether this is a local date/datetime value - no time zone is specified.static DateTimeValueReturns a string of the formorg.joda.time.DateTimeThis is a shortcut for#toDateTime(DateTimeZone.getDefault()).org.joda.time.DateTimetoDateTime(org.joda.time.DateTimeZone zone) Returns the datetime representation of this date-time value.Returns a string representation of the date or datetime in a format that is recognized by jodas ctors.Uses this local date time value (ex.toString()withZone(org.joda.time.DateTimeZone tz) Returns a newDateTimeValuewith the same millis and the specified time zone.
-
Constructor Details
-
DateTimeValue
public DateTimeValue(long millis, @Nullable @Nullable org.joda.time.DateTimeZone timezone, boolean datetime) Ctor.- Parameters:
millis- the millis as in UNIX timestamptimezone- the time zone (may be null to specifiy a local date)datetime- if this is a date-only (false) or datetime (true) value
-
-
Method Details
-
dateTime
Creates a date-time value with the information supplied by the instant. This will set the millis from the instant as well as the time zone. -
dateTime
Creates a date-time value from the specified local-time. This will set the milliseconds for the local date-time in time zone UTC. But no time zone is set into the returnedDateTimeValue. -
date
Creates a local date value. -
date
-
parse
-
withZone
Returns a newDateTimeValuewith the same millis and the specified time zone. -
isDate
public boolean isDate()Returns whether this represents a date-only value - no time information is specified. -
isDatetime
public boolean isDatetime()Returns whether this represents a date-time value. -
isLocal
public boolean isLocal()Returns whether this is a local date/datetime value - no time zone is specified. -
getTimezone
@Nullable public @Nullable org.joda.time.DateTimeZone getTimezone()Returns the time zone. Maybe null if this is a local datetime value. -
getMillis
public long getMillis()Returns the millis of this date-time value. -
toLocalDateTimeForUTC
Uses this local date time value (ex. 2005-10-22T15:40, discarding any time zone info) and carries it into the UTC time zone. The milliseconds are adopted to represent the new point in time. -
toDateTime
public org.joda.time.DateTime toDateTime(org.joda.time.DateTimeZone zone) Returns the datetime representation of this date-time value.
If this is a local/floating date-time value, the
DateTimewith the specified time zone is returned. The point in time is calculated to match the same local time in the specified time zone. -
toDateTime
public org.joda.time.DateTime toDateTime()This is a shortcut for#toDateTime(DateTimeZone.getDefault()).- Returns:
- joda's
DateTimefor this - See Also:
-
getUTCDateTime
public org.joda.time.DateTime getUTCDateTime()Returns this value asDateTimewith UTC time zone. -
getDateTimeAtStartOfDay
public org.joda.time.DateTime getDateTimeAtStartOfDay()Returns aDateTimeobject whose millis are set to the start of this day. IfisLocal()is true the UTC time zone is used. -
getDateTimeAtEndOfDay
public org.joda.time.DateTime getDateTimeAtEndOfDay()Returns aDateTimeobject whose millis are set to the end of this day. IfisLocal()is true the UTC time zone is used. -
isAfter
Returns whether this is after the specified value. Any date-only value the start of this day is used for comparing. It compares millis only. -
isBefore
Returns whether this is before the specified value. Any date-only value the start of this day is used for comparing. It compares millis only. -
isEqual
Returns whether this is equal the specified value. Any date-only value the start of this day is used for comparing. It compares millis only. -
toDateTimeString
Returns a string representation of the date or datetime in a format that is recognized by jodas ctors.
yyyy-MM-ddTHH:mmthe time information is optional.
The string returned can be parsed by
parse(String). -
toBasicDateTimeString
Returns a string of the formyyyyMMddTHHmmss[Z]where time is optional. The string is converted to UTC time zone! -
getWeekday
Returns the weekday of this date. -
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<DateTimeValue>
-
toString
-