Class DBDateTime
- All Implemented Interfaces:
DatetimeFilterData.MillisProvider
,Externalizable
,Serializable
,Comparable<DBDateTime>
A DBDateTime represents a zone-less, precise timepoint without respect to timezones. The
instant is stored as a signed 64-bit long, representing nanoseconds since the epoch (January 1, 1970, 00:00:00 GMT). This
provides a range from 1677-09-21T00:12:43.146-775807 UTC to 2262-04-11T23:47:16.854775807 UTC. The minimum long
value is reserved for QueryConstants.NULL_LONG
and therefore is not permitted as a valid DBDateTime.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new DBDatetime initialized to the epoch.DBDateTime
(long nanos) Create a new DBDateTime initialized to the provided nanoseconds since the epoch. -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(DBDateTime dateTime) boolean
getDate()
Deprecated.Convert this DBDateTime to a Java Instant.org.joda.time.DateTime
Deprecated.usetoZonedDateTime()
insteadorg.joda.time.DateTime
getJodaDateTime
(DBTimeZone timeZone) Deprecated.usetoZonedDateTime(ZoneId)
insteadlong
Get this time represented as microseconds since the epochlong
Get this time represented as milliseconds since the epochlong
getNanos()
Get this time represented as nanoseconds since the epochlong
Get nanoseconds-of-milliseconds; this number will always be between 0 and 999,999int
hashCode()
static DBDateTime
now()
Create a new DBDatetime initialized to the current time.static long
nowNanos()
Return the current time since the epoch in nanoseconds.void
Get the date represented by this DBDateTime in the defaultDBTimeZone
.toDateString
(DBTimeZone timeZone) Get the date represented by this DBDateTime in the givenDBTimeZone
.toDateString
(String zoneId) Get the date represented by this DBDateTime in the time zone specified byzoneId
inISO
date format.toDateString
(ZoneId timeZone) Get the date represented by this DBDateTime in the given javaZoneId
inISO
date format.toDateString
(org.joda.time.DateTimeZone timeZone) Get the date represented by this DBDateTime in the given JodaDateTimeZone
in ISO date format yyyy-mm.toLocalDate
(DBTimeZone zone) Get aLocalDate
representing the date of thisDBDateTime
at the specified time zone.toLocalDate
(String zone) Get aLocalDate
representing the date of thisDBDateTime
at the specified time zone.toLocalDate
(ZoneId zone) Get aLocalDate
representing the date of thisDBDateTime
at the specified time zone.toLocalTime
(DBTimeZone zone) Get aLocalTime
representing the time of day of thisDBDateTime
at the specified time zone.toLocalTime
(String zone) Get aLocalTime
representing the time of day of thisDBDateTime
at the specified time zone.toLocalTime
(ZoneId zone) Get aLocalTime
representing the time of day of thisDBDateTime
at the specified time zone.toString()
toString
(DBTimeZone timeZone) Convert this DBDateTime into a String using the providedDBTimeZone
.toZonedDateTime
(DBTimeZone zone) Get aZonedDateTime
version of thisDBDateTime
at the specified time zone.toZonedDateTime
(String zone) Get aZonedDateTime
version of thisDBDateTime
at the specified time zone.toZonedDateTime
(ZoneId zone) Get aZonedDateTime
version of thisDBDateTime
at the specified time zone.void
-
Constructor Details
-
DBDateTime
public DBDateTime()Create a new DBDatetime initialized to the epoch. -
DBDateTime
public DBDateTime(long nanos) Create a new DBDateTime initialized to the provided nanoseconds since the epoch.- Parameters:
nanos
- the number of nanoseconds since the epoch
-
-
Method Details
-
now
Create a new DBDatetime initialized to the current time.The precision of DBDateTime is nanoseconds, but the resolution of the now method is currently microseconds.
- Returns:
- a new DBDateTime initialized to the current time.
-
nowNanos
public static long nowNanos()Return the current time since the epoch in nanoseconds.The precision of DBDateTime is nanoseconds, but the resolution of the nowNanos method is currently microseconds.
- Returns:
- the nanoseconds used for new DBDateTime construction.
-
getNanos
public long getNanos()Get this time represented as nanoseconds since the epoch- Returns:
- the number of nanoseconds since the epoch
-
getMicros
public long getMicros()Get this time represented as microseconds since the epoch- Returns:
- the number of microseconds since the epoch
-
getMillis
public long getMillis()Get this time represented as milliseconds since the epoch- Specified by:
getMillis
in interfaceDatetimeFilterData.MillisProvider
- Returns:
- the number of milliseconds since the epoch
-
getNanosPartial
public long getNanosPartial()Get nanoseconds-of-milliseconds; this number will always be between 0 and 999,999- Returns:
- the number of nanoseconds after the nearest millisecond.
-
getJodaDateTime
Deprecated.usetoZonedDateTime()
insteadConvert this DBDateTime to a Joda DateTime. This DBDateTime will be truncated to milliseconds.- Returns:
- a Joda DateTime representing this DBDateTime
-
getJodaDateTime
Deprecated.usetoZonedDateTime(ZoneId)
insteadConvert this DBDateTime to a Joda DateTime. This DBDateTime will be truncated to milliseconds.- Parameters:
timeZone
- the timezone for the created Joda DateTime- Returns:
- a Joda DateTime representing this DBDateTime
-
toZonedDateTime
- Returns:
- a
ZonedDateTime
-
toZonedDateTime
Get aZonedDateTime
version of thisDBDateTime
at the specified time zone.- Returns:
- a
ZonedDateTime
-
toZonedDateTime
Get aZonedDateTime
version of thisDBDateTime
at the specified time zone.- Returns:
- a
ZonedDateTime
-
toZonedDateTime
Get aZonedDateTime
version of thisDBDateTime
at the specified time zone.- Returns:
- a
ZonedDateTime
-
toLocalDate
- Returns:
- the
LocalDate
-
toLocalDate
Get aLocalDate
representing the date of thisDBDateTime
at the specified time zone.- Returns:
- the
LocalDate
-
toLocalDate
Get aLocalDate
representing the date of thisDBDateTime
at the specified time zone.- Returns:
- the
LocalDate
-
toLocalDate
Get aLocalDate
representing the date of thisDBDateTime
at the specified time zone.- Returns:
- the
LocalDate
-
toLocalTime
- Returns:
- the
LocalTime
-
toLocalTime
Get aLocalTime
representing the time of day of thisDBDateTime
at the specified time zone.- Returns:
- the
LocalTime
-
toLocalTime
Get aLocalTime
representing the time of day of thisDBDateTime
at the specified time zone.- Returns:
- the
LocalTime
-
toLocalTime
Get aLocalTime
representing the time of day of thisDBDateTime
at the specified time zone.- Returns:
- the
LocalTime
-
getDate
Deprecated.usetoZonedDateTime()
instead.Convert this DBDateTime to a Java Date. This DBDateTime will be truncated to milliseconds.- Returns:
- a Java Date representing this DBDateTime
-
getInstant
Convert this DBDateTime to a Java Instant.- Returns:
- a Java Instant representing this DBDateTime
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<DBDateTime>
-
toString
-
toString
Convert this DBDateTime into a String using the providedDBTimeZone
.The date will be formatted as
yyyy-MM-DDThh:mm:ss.SSSSSSSSS TZ
, for example2020-05-27T13:37:57.780853000 NY
or2020-05-27T17:37:42.763641000 UTC
.- Parameters:
timeZone
- the timezone for formatting the string- Returns:
- a String representation of this DBDateTime
-
toDateString
Get the date represented by this DBDateTime in the defaultDBTimeZone
.- Returns:
- The date (yyyy-MM-dd) represented by this
DBDateTime
in the defaultDBTimeZone
.
-
toDateString
Get the date represented by this DBDateTime in the givenDBTimeZone
.- Parameters:
timeZone
- a DBTimeZone- Returns:
- The date (yyyy-MM-dd) represented by this
DBDateTime
in the given timeZone.
-
toDateString
Get the date represented by this DBDateTime in the given JodaDateTimeZone
in ISO date format yyyy-mm.- Parameters:
timeZone
- A joda DateTimeZone- Returns:
- The date (yyyy-MM-dd) represented by this
DBDateTime
in the giventimeZone
-
toDateString
Get the date represented by this DBDateTime in the time zone specified byzoneId
inISO
date format.- Parameters:
zoneId
- A java time zone ID string- Returns:
- The date (yyyy-MM-dd) represented by this
DBDateTime
in time zone represented by the givenzoneId
-
toDateString
Get the date represented by this DBDateTime in the given javaZoneId
inISO
date format.- Parameters:
timeZone
- A javatime zone ID
.- Returns:
- The date (yyyy-MM-dd) represented by this
DBDateTime
in the giventimeZone
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
-
toZonedDateTime()
instead.