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
ConstructorDescriptionDateTimeValue
(long millis, @Nullable org.joda.time.DateTimeZone timezone, boolean datetime) Ctor. -
Method Summary
Modifier and TypeMethodDescriptionint
static DateTimeValue
date
(org.joda.time.LocalDate date) Creates a local date value.static DateTimeValue
date
(org.joda.time.ReadableInstant datetime) static DateTimeValue
dateTime
(org.joda.time.LocalDateTime datetime) Creates a date-time value from the specified local-time.static DateTimeValue
dateTime
(org.joda.time.ReadableInstant instant) Creates a date-time value with the information supplied by the instant.boolean
org.joda.time.DateTime
Returns aDateTime
object whose millis are set to the end of this day.org.joda.time.DateTime
Returns aDateTime
object whose millis are set to the start of this day.long
Returns the millis of this date-time value.@Nullable org.joda.time.DateTimeZone
Returns the time zone.org.joda.time.DateTime
Returns this value asDateTime
with UTC time zone.Returns the weekday of this date.int
hashCode()
boolean
isAfter
(DateTimeValue dt) Returns whether this is after the specified value.boolean
Returns whether this is before the specified value.boolean
isDate()
Returns whether this represents a date-only value - no time information is specified.boolean
Returns whether this represents a date-time value.boolean
isEqual
(DateTimeValue dt) Returns whether this is equal the specified value.boolean
isLocal()
Returns whether this is a local date/datetime value - no time zone is specified.static DateTimeValue
Returns a string of the formorg.joda.time.DateTime
This is a shortcut for#toDateTime(DateTimeZone.getDefault())
.org.joda.time.DateTime
toDateTime
(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 newDateTimeValue
with 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 newDateTimeValue
with 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
DateTime
with 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
DateTime
for this - See Also:
-
getUTCDateTime
public org.joda.time.DateTime getUTCDateTime()Returns this value asDateTime
with UTC time zone. -
getDateTimeAtStartOfDay
public org.joda.time.DateTime getDateTimeAtStartOfDay()Returns aDateTime
object 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 aDateTime
object 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:mm
the 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:
compareTo
in interfaceComparable<DateTimeValue>
-
toString
-