The Date
object to convert
new DataAPITime(new Date('2004-09-14T12:00:00.000')) // '12:00:00.000000000'
time(new Date('12:34:56.78')) // '12:34:56.780000000'
Parses a DataAPITime
from a string in the format HH:MM[:SS[.NNNNNNNNN]]
.
See DataAPITime for more info about the exact format.
The time string to parse
new DataAPITime('12:00') // '12:00:00.000000000'
time('12:34:56.78') // '12:34:56.780000000'
Internal
Should not be called by user directly.
Creates a DataAPITime
from an hour, a minute, and optional second and nanosecond components.
All components must be zero-indexed positive integers within the following ranges:
hour
: [0, 23]minute
: [0, 59]second
: [0, 59]nanosecond
: [0, 999,999,999]The hour to use
The minute to use
Optional
seconds: numberThe second to use (defaults to 0)
Optional
nanoseconds: numberThe nanosecond to use (defaults to 0)
new DataAPIDate(20, 15) // '20:15:00.000000000'
date(12, 12, 12, 12) // '12:12:12.000000012'
Readonly
hoursThe hour component of this DataAPITime
.
Must be between 0-23.
Readonly
minutesThe minute component of this DataAPITime
.
Must be between 0-59.
Readonly
nanosecondsThe nanosecond component of this DataAPITime
.
Must be between 0-999,999,999.
Readonly
secondsThe second component of this DataAPITime
.
Must be between 0-59.
Errorful implementation of $SerializeForCollection
for TableCodec
Throws a human-readable error message warning that this datatype may not be used with collections without writing a custom ser/des codec.
Implementation of $SerializeForTable
for TableCodec
The other DataAPITime
to compare to
0
if the times are equal, -1
if this time is before the other, and 1
if this time is after the other
time('12:00').compare(time(12, 0)) // 0
time('12:00').compare(time(12, 1)) // -1
time('12:01').compare(time(12, 0)) // 1
The other DataAPITime
to compare to
true
if the times are equal, and false
otherwise
time('12:00').equals(time(12, 0)) // true
time('12:00').equals(time(12, 1)) // false
time('12:00').equals('12:00:00.000000000') // true
Converts this DataAPITime
to a Date
object in the local timezone.
If no base
date is provided, the time component defaults to the current local date.
If the base
parameter is a DataAPIDate
, it is interpreted as being in the local timezone, not UTC.
See DataAPITime.toDateUTC for a UTC-based alternative to this method.
Optional
base: Date | DataAPIDateThe base date to use for the date component. If omitted, defaults to the current local date.
The Date
object representing this DataAPITime
in the local timezone.
// Assuming the local timezone is UTC-6 (CST) //
// Local Time: '2000-01-01T12:00:00'
// UTC Time: '2000-01-01T18:00:00Z'
time('12:00:00').toDate(new Date('2000-01-01T00:00:00'));
// Local Time: '1999-12-31T12:00:00'
// UTC Time: '1999-12-31T18:00:00Z'
time('12:00:00').toDate(new Date('2000-01-01T00:00:00Z'));
// Local Time: '2000-01-01T12:00:00'
// UTC Time: '2000-01-01T18:00:00Z'
time('12:00:00').toDate(new DataAPIDate('2000-01-01'));
// Local Time: '2025-01-22T12:00:00'
// UTC Time: '2025-01-22T18:00:00Z'
time('12:00:00').toDate();
DataAPITime.toDateUTC
Converts this DataAPITime
to a Date
object in UTC.
If no base
date is provided, the time component defaults to the current date in UTC.
If the base
parameter is a DataAPIDate
, it is interpreted as being in the UTC timezone.
See DataAPITime.toDate for a local-date-based alternative to this method.
Optional
base: Date | DataAPIDateThe base date to use for the date component. If omitted, defaults to the current date in UTC.
The Date
object representing this DataAPITime
in UTC.
// Assuming the local timezone is UTC-6 (CST) //
// Local Time: '2000-01-01T06:00:00'
// UTC Time: '2000-01-01T12:00:00Z'
time('12:00:00').toDateUTC(new Date('2000-01-01T00:00:00'));
// Local Time: '2000-01-01T06:00:00Z'
// UTC Time: '2000-01-01T12:00:00Z'
time('12:00:00').toDateUTC(new Date('2000-01-01T00:00:00Z'));
// Local Time: '2000-01-01T06:00:00'
// UTC Time: '2000-01-01T12:00:00Z'
time('12:00:00').toDateUTC(new DataAPIDate('2000-01-01'));
// Local Time: '2025-01-22T06:00:00'
// UTC Time: '2025-01-22T12:00:00Z'
time('12:00:00').toDateUTC();
DataAPITime.toDate
Returns the string representation of this DataAPITime
Note that it'll contain the second & nanosecond components, even if they weren't provided.
The string representation of this DataAPITime
time('12:00').toString() // '12:00:00.000000000'
time(12, 34, 56, 78).toString() // '12:34:56.000000078'
Static
[$Implementation of $DeserializeForTable
for TableCodec
Static
nowThe current time in the local timezone
const now = time.now();
// or
const now = DataAPITime.now()
Static
ofCreates a DataAPITime
from the number of nanoseconds since the start of the day .
The number must be a positive integer in the range [0, 86,399,999,999,999].
The number of nanoseconds since the start of the day
The DataAPITime
representing the given number of nanoseconds
DataAPITime.ofNanoOfDay(0) // '00:00:00.000000000'
date.ofNanoOfDay(12_345_678_912_345) // '03:25:45.678912345'
Static
ofCreates a DataAPITime
from the number of seconds since the start of the day.
The number must be a positive integer in the range [0, 86,399].
The number of seconds since the start of the day
The DataAPITime
representing the given number of seconds
DataAPITime.ofSecondOfDay(0) // '00:00:00.000000000'
DataAPITime.ofSecondOfDay(12_345) // '03:25:45.000000000'
Static
utcnowThe current time in UTC
const now = time.utcnow();
// or
const now = DataAPITime.utcnow()
Overview
Represents a
time
column for Data API tables.Format
time
s consist of an hour, a minute, and optional second and nanosecond components.12:34:56.789
is equivalent to12:34:56.789000000
.Together, the format would be as such:
HH:MM[:SS[.NNNNNNNNN]]
.Creation
There are a number of different ways to initialize a
DataAPITime
:Example
The
time
shorthandYou may use the time shorthand function-object anywhere when creating new
DataAPITime
s.Example
See the official DataStax documentation for more information.
See
time