object DateTimeUtils
Helper functions for converting between internal and external date and time representations. Dates are exposed externally as java.sql.Date and are represented internally as the number of dates since the Unix epoch (1970-01-01). Timestamps are exposed externally as java.sql.Timestamp and are stored internally as longs, which are capable of storing timestamps with microsecond precision.
- Alphabetic
- By Inheritance
- DateTimeUtils
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final val JULIAN_DAY_OF_EPOCH: Int(2440588)
- final val MICROS_PER_DAY: Long
- final val MICROS_PER_MILLIS: Long(1000L)
- final val MICROS_PER_SECOND: Long
- final val MILLIS_PER_DAY: Long
- final val MILLIS_PER_SECOND: Long(1000L)
- final val MonthOf31Days: Set[Int]
- final val NANOS_PER_MICROS: Long(1000L)
- final val NANOS_PER_SECOND: Long
- final val SECONDS_PER_DAY: Long
- val TIMEZONE_OPTION: String
- final val TimeZoneGMT: TimeZone
- final val TimeZoneUTC: TimeZone
- final val YearZero: Int(-17999)
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
- def convertTz(ts: SQLTimestamp, fromZone: TimeZone, toZone: TimeZone): SQLTimestamp
Convert the timestamp
ts
from one timezone to another.Convert the timestamp
ts
from one timezone to another.TODO: Because of DST, the conversion between UTC and human time is not exactly one-to-one mapping, the conversion here may return wrong result, we should make the timestamp timezone-aware.
- def dateAddMonths(days: SQLDate, months: Int): SQLDate
Add date and year-month interval.
Add date and year-month interval. Returns a date value, expressed in days since 1.1.1970.
- def dateToString(days: SQLDate, timeZone: TimeZone): String
- def dateToString(days: SQLDate): String
- final val daysIn400Years: Int
- def daysToMillis(days: SQLDate, timeZone: TimeZone): Long
- def daysToMillis(days: SQLDate): Long
- def defaultTimeZone(): TimeZone
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def fromJavaDate(date: Date): SQLDate
Returns the number of days since epoch from java.sql.Date.
- def fromJavaTimestamp(t: Timestamp): SQLTimestamp
Returns the number of micros since epoch from java.sql.Timestamp.
- def fromJulianDay(day: Int, nanoseconds: Long): SQLTimestamp
Returns the number of microseconds since epoch from Julian day and nanoseconds in a day
- def fromMillis(millis: Long): SQLTimestamp
- def fromUTCTime(time: SQLTimestamp, timeZone: String): SQLTimestamp
Returns a timestamp of given timezone from utc timestamp, with the same string representation in their timezone.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- def getDayInYear(date: SQLDate): Int
Returns the 'day in year' value for the given date.
Returns the 'day in year' value for the given date. The date is expressed in days since 1.1.1970.
- def getDayOfMonth(date: SQLDate): Int
Returns the 'day of month' value for the given date.
Returns the 'day of month' value for the given date. The date is expressed in days since 1.1.1970.
- def getDayOfWeekFromString(string: String): Int
- def getHours(microsec: SQLTimestamp, timeZone: TimeZone): Int
Returns the hour value of a given timestamp value.
Returns the hour value of a given timestamp value. The timestamp is expressed in microseconds.
- def getHours(microsec: SQLTimestamp): Int
Returns the hour value of a given timestamp value.
Returns the hour value of a given timestamp value. The timestamp is expressed in microseconds.
- def getLastDayOfMonth(date: SQLDate): SQLDate
Returns last day of the month for the given date.
Returns last day of the month for the given date. The date is expressed in days since 1.1.1970.
- def getMinutes(microsec: SQLTimestamp, timeZone: TimeZone): Int
Returns the minute value of a given timestamp value.
Returns the minute value of a given timestamp value. The timestamp is expressed in microseconds.
- def getMinutes(microsec: SQLTimestamp): Int
Returns the minute value of a given timestamp value.
Returns the minute value of a given timestamp value. The timestamp is expressed in microseconds.
- def getMonth(date: SQLDate): Int
Returns the month value for the given date.
Returns the month value for the given date. The date is expressed in days since 1.1.1970. January is month 1.
- def getNextDateForDayOfWeek(startDate: SQLDate, dayOfWeek: Int): SQLDate
Returns the first date which is later than startDate and is of the given dayOfWeek.
Returns the first date which is later than startDate and is of the given dayOfWeek. dayOfWeek is an integer ranges in [0, 6], and 0 is Thu, 1 is Fri, etc,.
- def getQuarter(date: SQLDate): Int
Returns the quarter for the given date.
Returns the quarter for the given date. The date is expressed in days since 1.1.1970.
- def getSeconds(microsec: SQLTimestamp, timeZone: TimeZone): Int
Returns the second value of a given timestamp value.
Returns the second value of a given timestamp value. The timestamp is expressed in microseconds.
- def getSeconds(microsec: SQLTimestamp): Int
Returns the second value of a given timestamp value.
Returns the second value of a given timestamp value. The timestamp is expressed in microseconds.
- def getThreadLocalDateFormat(timeZone: TimeZone): DateFormat
- def getThreadLocalTimestampFormat(timeZone: TimeZone): DateFormat
- def getTimeZone(timeZoneId: String): TimeZone
- def getYear(date: SQLDate): Int
Returns the year value for the given date.
Returns the year value for the given date. The date is expressed in days since 1.1.1970.
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def millisToDays(millisUtc: Long, timeZone: TimeZone): SQLDate
- def millisToDays(millisUtc: Long): SQLDate
- def monthsBetween(time1: SQLTimestamp, time2: SQLTimestamp, roundOff: Boolean, timeZone: TimeZone): Double
Returns number of months between time1 and time2.
Returns number of months between time1 and time2. time1 and time2 are expressed in microseconds since 1.1.1970. If time1 is later than time2, the result is positive.
If time1 and time2 are on the same day of month, or both are the last day of month, returns, time of day will be ignored.
Otherwise, the difference is calculated based on 31 days per month. The result is rounded to 8 decimal places if
roundOff
is set to true. - final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- def parseTruncLevel(format: String): Int
Returns the truncate level, could be TRUNC_YEAR, TRUNC_MONTH, TRUNC_TO_DAY, TRUNC_TO_HOUR, TRUNC_TO_MINUTE, TRUNC_TO_SECOND, TRUNC_TO_WEEK, TRUNC_TO_QUARTER or TRUNC_INVALID, TRUNC_INVALID means unsupported truncate level.
- def splitDate(date: SQLDate): (Int, Int, Int, Int)
Split date (expressed in days since 1.1.1970) into four fields: year, month (Jan is Month 1), dayInMonth, daysToMonthEnd (0 if it's last day of month).
- def stringToDate(s: String): Option[SQLDate]
Trim and parse a given UTF8 date string to a corresponding Int value.
Trim and parse a given UTF8 date string to a corresponding Int value. The return type is Option in order to distinguish between 0 and null. The following formats are allowed:
yyyy
yyyy-[m]m
yyyy-[m]m-[d]d
yyyy-[m]m-[d]d
yyyy-[m]m-[d]d *
yyyy-[m]m-[d]dT*
- def stringToLocalDateTime(s: String): Option[LocalDateTime]
- def stringToOffsetDateTime(s: String): Option[OffsetDateTime]
- def stringToTimestamp(s: String, timeZone: TimeZone): Option[SQLTimestamp]
- def stringToTimestamp(s: String): Option[SQLTimestamp]
Trim and parse a given UTF8 date string to the corresponding a corresponding Long value.
Trim and parse a given UTF8 date string to the corresponding a corresponding Long value. The return type is Option in order to distinguish between 0L and null. The following formats are allowed:
yyyy
yyyy-[m]m
yyyy-[m]m-[d]d
yyyy-[m]m-[d]d
yyyy-[m]m-[d]d [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]
yyyy-[m]m-[d]d [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]Z
yyyy-[m]m-[d]d [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]-[h]h:[m]m
yyyy-[m]m-[d]d [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]+[h]h:[m]m
yyyy-[m]m-[d]dT[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]
yyyy-[m]m-[d]dT[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]Z
yyyy-[m]m-[d]dT[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]-[h]h:[m]m
yyyy-[m]m-[d]dT[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]+[h]h:[m]m
[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]
[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]Z
[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]-[h]h:[m]m
[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]+[h]h:[m]m
T[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]
T[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]Z
T[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]-[h]h:[m]m
T[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]+[h]h:[m]m
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def timestampAddInterval(start: SQLTimestamp, months: Int, microseconds: Long, timeZone: TimeZone): SQLTimestamp
Add timestamp and full interval.
Add timestamp and full interval. Returns a timestamp value, expressed in microseconds since 1.1.1970 00:00:00.
- def timestampAddInterval(start: SQLTimestamp, months: Int, microseconds: Long): SQLTimestamp
Add timestamp and full interval.
Add timestamp and full interval. Returns a timestamp value, expressed in microseconds since 1.1.1970 00:00:00.
- def timestampToString(us: SQLTimestamp, timeZone: TimeZone): String
- def timestampToString(us: SQLTimestamp): String
- final val to2001: Int(-11323)
- def toJavaDate(daysSinceEpoch: SQLDate): Date
Returns a java.sql.Date from number of days since epoch.
- def toJavaTimestamp(us: SQLTimestamp): Timestamp
Returns a java.sql.Timestamp from number of micros since epoch.
- def toJulianDay(us: SQLTimestamp): (Int, Long)
Returns Julian day and nanoseconds in a day from the number of microseconds
Returns Julian day and nanoseconds in a day from the number of microseconds
Note: support timestamp since 4717 BC (without negative nanoseconds, compatible with Hive).
- def toMillis(us: SQLTimestamp): Long
- def toString(): String
- Definition Classes
- AnyRef → Any
- def toUTCTime(time: SQLTimestamp, timeZone: String): SQLTimestamp
Returns a utc timestamp from a given timestamp from a given timezone, with the same string representation in their timezone.
- final val toYearZero: Int
- def truncDate(d: SQLDate, level: Int): SQLDate
Returns the trunc date from original date and trunc level.
Returns the trunc date from original date and trunc level. Trunc level should be generated using
parseTruncLevel()
, should only be 1 or 2. - def truncTimestamp(d: SQLTimestamp, level: Int): SQLTimestamp
- def truncTimestamp(t: SQLTimestamp, level: Int, timeZone: TimeZone): SQLTimestamp
Returns the trunc date time from original date time and trunc level.
Returns the trunc date time from original date time and trunc level. Trunc level should be generated using
parseTruncLevel()
, should be between 1 and 8 - final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)