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) boolean@NotNull DategetDate()Deprecated.@NotNull InstantConvert this DBDateTime to a Java Instant.org.joda.time.DateTimeDeprecated.usetoZonedDateTime()insteadorg.joda.time.DateTimegetJodaDateTime(@NotNull 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.void@NotNull StringGet the date represented by this DBDateTime in the defaultDBTimeZone.@NotNull StringtoDateString(@NotNull DBTimeZone timeZone) Get the date represented by this DBDateTime in the givenDBTimeZone.@NotNull StringtoDateString(@NotNull String zoneId) Get the date represented by this DBDateTime in the time zone specified byzoneIdinISOdate format.@NotNull StringtoDateString(@NotNull ZoneId timeZone) Get the date represented by this DBDateTime in the given javaZoneIdinISOdate format.@NotNull StringtoDateString(@NotNull org.joda.time.DateTimeZone timeZone) Get the date represented by this DBDateTime in the given JodaDateTimeZonein ISO date format yyyy-mm.@NotNull LocalDate@NotNull LocalDatetoLocalDate(@NotNull DBTimeZone zone) Get aLocalDaterepresenting the date of thisDBDateTimeat the specified time zone.@NotNull LocalDatetoLocalDate(@NotNull String zone) Get aLocalDaterepresenting the date of thisDBDateTimeat the specified time zone.@NotNull LocalDatetoLocalDate(@NotNull ZoneId zone) Get aLocalDaterepresenting the date of thisDBDateTimeat the specified time zone.@NotNull LocalTime@NotNull LocalTimetoLocalTime(@NotNull DBTimeZone zone) Get aLocalTimerepresenting the time of day of thisDBDateTimeat the specified time zone.@NotNull LocalTimetoLocalTime(@NotNull String zone) Get aLocalTimerepresenting the time of day of thisDBDateTimeat the specified time zone.@NotNull LocalTimetoLocalTime(@NotNull ZoneId zone) Get aLocalTimerepresenting the time of day of thisDBDateTimeat the specified time zone.toString()@NotNull StringtoString(@NotNull DBTimeZone timeZone) Convert this DBDateTime into a String using the providedDBTimeZone.@NotNull ZonedDateTime@NotNull ZonedDateTimetoZonedDateTime(@NotNull DBTimeZone zone) Get aZonedDateTimeversion of thisDBDateTimeat the specified time zone.@NotNull ZonedDateTimetoZonedDateTime(@NotNull String zone) Get aZonedDateTimeversion of thisDBDateTimeat the specified time zone.@NotNull ZonedDateTimetoZonedDateTime(@NotNull 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.