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 TypeMethodDescriptionintcompareTo(DBDateTime dateTime) booleangetDate()Deprecated.Convert this DBDateTime to a Java Instant.org.joda.time.DateTimeDeprecated.usetoZonedDateTime()insteadorg.joda.time.DateTimegetJodaDateTime(DBTimeZone timeZone) Deprecated.usetoZonedDateTime(ZoneId)insteadlongGet this time represented as microseconds since the epochlongGet this time represented as milliseconds since the epochlonggetNanos()Get this time represented as nanoseconds since the epochlongGet nanoseconds-of-milliseconds; this number will always be between 0 and 999,999inthashCode()static DBDateTimenow()Create a new DBDatetime initialized to the current time.static longnowNanos()Return the current time since the epoch in nanoseconds.voidGet 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 byzoneIdinISOdate format.toDateString(ZoneId timeZone) Get the date represented by this DBDateTime in the given javaZoneIdinISOdate format.toDateString(org.joda.time.DateTimeZone timeZone) Get the date represented by this DBDateTime in the given JodaDateTimeZonein ISO date format yyyy-mm.toLocalDate(DBTimeZone zone) Get aLocalDaterepresenting the date of thisDBDateTimeat the specified time zone.toLocalDate(String zone) Get aLocalDaterepresenting the date of thisDBDateTimeat the specified time zone.toLocalDate(ZoneId zone) Get aLocalDaterepresenting the date of thisDBDateTimeat the specified time zone.toLocalTime(DBTimeZone zone) Get aLocalTimerepresenting the time of day of thisDBDateTimeat the specified time zone.toLocalTime(String zone) Get aLocalTimerepresenting the time of day of thisDBDateTimeat the specified time zone.toLocalTime(ZoneId zone) Get aLocalTimerepresenting the time of day of thisDBDateTimeat the specified time zone.toString()toString(DBTimeZone timeZone) Convert this DBDateTime into a String using the providedDBTimeZone.toZonedDateTime(DBTimeZone zone) Get aZonedDateTimeversion of thisDBDateTimeat the specified time zone.toZonedDateTime(String zone) Get aZonedDateTimeversion of thisDBDateTimeat the specified time zone.toZonedDateTime(ZoneId zone) Get aZonedDateTimeversion of thisDBDateTimeat 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:
getMillisin 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 aZonedDateTimeversion of thisDBDateTimeat the specified time zone.- Returns:
- a
ZonedDateTime
-
toZonedDateTime
Get aZonedDateTimeversion of thisDBDateTimeat the specified time zone.- Returns:
- a
ZonedDateTime
-
toZonedDateTime
Get aZonedDateTimeversion of thisDBDateTimeat the specified time zone.- Returns:
- a
ZonedDateTime
-
toLocalDate
- Returns:
- the
LocalDate
-
toLocalDate
Get aLocalDaterepresenting the date of thisDBDateTimeat the specified time zone.- Returns:
- the
LocalDate
-
toLocalDate
Get aLocalDaterepresenting the date of thisDBDateTimeat the specified time zone.- Returns:
- the
LocalDate
-
toLocalDate
Get aLocalDaterepresenting the date of thisDBDateTimeat the specified time zone.- Returns:
- the
LocalDate
-
toLocalTime
- Returns:
- the
LocalTime
-
toLocalTime
Get aLocalTimerepresenting the time of day of thisDBDateTimeat the specified time zone.- Returns:
- the
LocalTime
-
toLocalTime
Get aLocalTimerepresenting the time of day of thisDBDateTimeat the specified time zone.- Returns:
- the
LocalTime
-
toLocalTime
Get aLocalTimerepresenting the time of day of thisDBDateTimeat 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:
compareToin 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 NYor2020-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
DBDateTimein 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
DBDateTimein the given timeZone.
-
toDateString
Get the date represented by this DBDateTime in the given JodaDateTimeZonein ISO date format yyyy-mm.- Parameters:
timeZone- A joda DateTimeZone- Returns:
- The date (yyyy-MM-dd) represented by this
DBDateTimein the giventimeZone
-
toDateString
Get the date represented by this DBDateTime in the time zone specified byzoneIdinISOdate format.- Parameters:
zoneId- A java time zone ID string- Returns:
- The date (yyyy-MM-dd) represented by this
DBDateTimein time zone represented by the givenzoneId
-
toDateString
Get the date represented by this DBDateTime in the given javaZoneIdinISOdate format.- Parameters:
timeZone- A javatime zone ID.- Returns:
- The date (yyyy-MM-dd) represented by this
DBDateTimein the giventimeZone
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOException
-
toZonedDateTime()instead.