@fuel-ts/utils .DateTime
This class is used to represent a date and time in the Tai64 format.
import { DateTime } from 'fuels';
// Constants
const tai64 = '4611686020108779340';
const unixMilliseconds = 1681391398000;
const seconds = 1681391398;
// Instantiation
let date: DateTime = DateTime.now();
date = DateTime.fromTai64(tai64);
date = DateTime.fromUnixMilliseconds(unixMilliseconds);
date = DateTime.fromUnixSeconds(seconds);
// Utility functions
tai64.toTai64() // '4611686020108779340'
milliseconds.toUnixMilliseconds() // 1681391398000
seconds.toUnixSeconds() // 1681391398
// All date methods are available
const now: Date = DateTime.now();
now.toISOString(); // '2023-04-13T13:09:58.000Z'
now.getTime(); // 1681391398000
Date
↳ DateTime
Date
• new DateTime(date
): DateTime
Hide the constructor to prevent direct instantiation.
Name | Type |
---|---|
date | string | number | Date |
Date.constructor
packages/utils/src/utils/date-time.ts:130
▪ Static
TAI64_NULL: string
= ''
packages/utils/src/utils/date-time.ts:99
▸ [toPrimitive](hint
): string
Converts a Date object to a string.
Name | Type |
---|---|
hint | "default" |
string
Date.[toPrimitive]
Date.[toPrimitive]
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:116
▸ [toPrimitive](hint
): string
Converts a Date object to a string.
Name | Type |
---|---|
hint | "string" |
string
Date.[toPrimitive]
Date.[toPrimitive]
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:120
▸ [toPrimitive](hint
): number
Converts a Date object to a number.
Name | Type |
---|---|
hint | "number" |
number
Date.[toPrimitive]
Date.[toPrimitive]
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:124
▸ [toPrimitive](hint
): string
| number
Converts a Date object to a string or number.
Throws
If 'hint' was given something other than "number", "string", or "default".
Name | Type | Description |
---|---|---|
hint | string | The strings "number", "string", or "default" to specify what primitive to return. |
string
| number
A number if 'hint' was "number", a string if 'hint' was "string" or "default".
Date.[toPrimitive]
Date.[toPrimitive]
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:133
▸ getDate(): number
Gets the day-of-the-month, using local time.
number
Date.getDate
Date.getDate
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:789
▸ getDay(): number
Gets the day of the week, using local time.
number
Date.getDay
Date.getDay
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:793
▸ getFullYear(): number
Gets the year, using local time.
number
Date.getFullYear
Date.getFullYear
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:781
▸ getHours(): number
Gets the hours in a date, using local time.
number
Date.getHours
Date.getHours
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:797
▸ getMilliseconds(): number
Gets the milliseconds of a Date, using local time.
number
Date.getMilliseconds
Date.getMilliseconds
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:809
▸ getMinutes(): number
Gets the minutes of a Date object, using local time.
number
Date.getMinutes
Date.getMinutes
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:801
▸ getMonth(): number
Gets the month, using local time.
number
Date.getMonth
Date.getMonth
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:785
▸ getSeconds(): number
Gets the seconds of a Date object, using local time.
number
Date.getSeconds
Date.getSeconds
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:805
▸ getTime(): number
Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
number
Date.getTime
Date.getTime
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:779
▸ getTimezoneOffset(): number
Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC).
number
Date.getTimezoneOffset
Date.getTimezoneOffset
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:813
▸ getUTCDate(): number
Gets the day-of-the-month, using Universal Coordinated Time (UTC).
number
Date.getUTCDate
Date.getUTCDate
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:791
▸ getUTCDay(): number
Gets the day of the week using Universal Coordinated Time (UTC).
number
Date.getUTCDay
Date.getUTCDay
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:795
▸ getUTCFullYear(): number
Gets the year using Universal Coordinated Time (UTC).
number
Date.getUTCFullYear
Date.getUTCFullYear
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:783
▸ getUTCHours(): number
Gets the hours value in a Date object using Universal Coordinated Time (UTC).
number
Date.getUTCHours
Date.getUTCHours
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:799
▸ getUTCMilliseconds(): number
Gets the milliseconds of a Date object using Universal Coordinated Time (UTC).
number
Date.getUTCMilliseconds
Date.getUTCMilliseconds
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:811
▸ getUTCMinutes(): number
Gets the minutes of a Date object using Universal Coordinated Time (UTC).
number
Date.getUTCMinutes
Date.getUTCMinutes
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:803
▸ getUTCMonth(): number
Gets the month of a Date object using Universal Coordinated Time (UTC).
number
Date.getUTCMonth
Date.getUTCMonth
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:787
▸ getUTCSeconds(): number
Gets the seconds of a Date object using Universal Coordinated Time (UTC).
number
Date.getUTCSeconds
Date.getUTCSeconds
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:807
▸ setDate(date
): number
Sets the numeric day-of-the-month value of the Date object using local time.
Name | Type | Description |
---|---|---|
date | number | A numeric value equal to the day of the month. |
number
Date.setDate
Date.setDate
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:876
▸ setFullYear(year
, month?
, date?
): number
Sets the year of the Date object using local time.
Name | Type | Description |
---|---|---|
year | number | A numeric value for the year. |
month? | number | A zero-based numeric value for the month (0 for January, 11 for December). Must be specified if numDate is specified. |
date? | number | A numeric value equal for the day of the month. |
number
Date.setFullYear
Date.setFullYear
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:900
▸ setHours(hours
, min?
, sec?
, ms?
): number
Sets the hour value in the Date object using local time.
Name | Type | Description |
---|---|---|
hours | number | A numeric value equal to the hours value. |
min? | number | A numeric value equal to the minutes value. |
sec? | number | A numeric value equal to the seconds value. |
ms? | number | A numeric value equal to the milliseconds value. |
number
Date.setHours
Date.setHours
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:863
▸ setMilliseconds(ms
): number
Sets the milliseconds value in the Date object using local time.
Name | Type | Description |
---|---|---|
ms | number | A numeric value equal to the millisecond value. |
number
Date.setMilliseconds
Date.setMilliseconds
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:823
▸ setMinutes(min
, sec?
, ms?
): number
Sets the minutes value in the Date object using local time.
Name | Type | Description |
---|---|---|
min | number | A numeric value equal to the minutes value. |
sec? | number | A numeric value equal to the seconds value. |
ms? | number | A numeric value equal to the milliseconds value. |
number
Date.setMinutes
Date.setMinutes
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:848
▸ setMonth(month
, date?
): number
Sets the month value in the Date object using local time.
Name | Type | Description |
---|---|---|
month | number | A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. |
date? | number | A numeric value representing the day of the month. If this value is not supplied, the value from a call to the getDate method is used. |
number
Date.setMonth
Date.setMonth
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:887
▸ setSeconds(sec
, ms?
): number
Sets the seconds value in the Date object using local time.
Name | Type | Description |
---|---|---|
sec | number | A numeric value equal to the seconds value. |
ms? | number | A numeric value equal to the milliseconds value. |
number
Date.setSeconds
Date.setSeconds
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:835
▸ setTime(time
): number
Sets the date and time value in the Date object.
Name | Type | Description |
---|---|---|
time | number | A numeric value representing the number of elapsed milliseconds since midnight, January 1, 1970 GMT. |
number
Date.setTime
Date.setTime
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:818
▸ setUTCDate(date
): number
Sets the numeric day of the month in the Date object using Universal Coordinated Time (UTC).
Name | Type | Description |
---|---|---|
date | number | A numeric value equal to the day of the month. |
number
Date.setUTCDate
Date.setUTCDate
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:881
▸ setUTCFullYear(year
, month?
, date?
): number
Sets the year value in the Date object using Universal Coordinated Time (UTC).
Name | Type | Description |
---|---|---|
year | number | A numeric value equal to the year. |
month? | number | A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. Must be supplied if numDate is supplied. |
date? | number | A numeric value equal to the day of the month. |
number
Date.setUTCFullYear
Date.setUTCFullYear
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:907
▸ setUTCHours(hours
, min?
, sec?
, ms?
): number
Sets the hours value in the Date object using Universal Coordinated Time (UTC).
Name | Type | Description |
---|---|---|
hours | number | A numeric value equal to the hours value. |
min? | number | A numeric value equal to the minutes value. |
sec? | number | A numeric value equal to the seconds value. |
ms? | number | A numeric value equal to the milliseconds value. |
number
Date.setUTCHours
Date.setUTCHours
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:871
▸ setUTCMilliseconds(ms
): number
Sets the milliseconds value in the Date object using Universal Coordinated Time (UTC).
Name | Type | Description |
---|---|---|
ms | number | A numeric value equal to the millisecond value. |
number
Date.setUTCMilliseconds
Date.setUTCMilliseconds
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:828
▸ setUTCMinutes(min
, sec?
, ms?
): number
Sets the minutes value in the Date object using Universal Coordinated Time (UTC).
Name | Type | Description |
---|---|---|
min | number | A numeric value equal to the minutes value. |
sec? | number | A numeric value equal to the seconds value. |
ms? | number | A numeric value equal to the milliseconds value. |
number
Date.setUTCMinutes
Date.setUTCMinutes
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:855
▸ setUTCMonth(month
, date?
): number
Sets the month value in the Date object using Universal Coordinated Time (UTC).
Name | Type | Description |
---|---|---|
month | number | A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. |
date? | number | A numeric value representing the day of the month. If it is not supplied, the value from a call to the getUTCDate method is used. |
number
Date.setUTCMonth
Date.setUTCMonth
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:893
▸ setUTCSeconds(sec
, ms?
): number
Sets the seconds value in the Date object using Universal Coordinated Time (UTC).
Name | Type | Description |
---|---|---|
sec | number | A numeric value equal to the seconds value. |
ms? | number | A numeric value equal to the milliseconds value. |
number
Date.setUTCSeconds
Date.setUTCSeconds
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:841
▸ toDateString(): string
Returns a date as a string value.
string
Date.toDateString
Date.toDateString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:767
▸ toISOString(): string
Returns a date as a string value in ISO format.
string
Date.toISOString
Date.toISOString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:911
▸ toJSON(key?
): string
Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization.
Name | Type |
---|---|
key? | any |
string
Date.toJSON
Date.toJSON
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:913
▸ toLocaleDateString(): string
Returns a date as a string value appropriate to the host environment's current locale.
string
Date.toLocaleDateString
Date.toLocaleDateString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:773
▸ toLocaleDateString(locales?
, options?
): string
Converts a date to a string by using the current or specified locale.
Name | Type | Description |
---|---|---|
locales? | string | string [] | A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. |
options? | DateTimeFormatOptions | An object that contains one or more properties that specify comparison options. |
string
Date.toLocaleDateString
Date.toLocaleDateString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:4546
▸ toLocaleDateString(locales?
, options?
): string
Converts a date to a string by using the current or specified locale.
Name | Type | Description |
---|---|---|
locales? | LocalesArgument | A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. |
options? | DateTimeFormatOptions | An object that contains one or more properties that specify comparison options. |
string
Date.toLocaleDateString
Date.toLocaleDateString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es2020.date.d.ts:34
▸ toLocaleString(): string
Returns a value as a string value appropriate to the host environment's current locale.
string
Date.toLocaleString
Date.toLocaleString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:771
▸ toLocaleString(locales?
, options?
): string
Converts a date and time to a string by using the current or specified locale.
Name | Type | Description |
---|---|---|
locales? | string | string [] | A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. |
options? | DateTimeFormatOptions | An object that contains one or more properties that specify comparison options. |
string
Date.toLocaleString
Date.toLocaleString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:4540
▸ toLocaleString(locales?
, options?
): string
Converts a date and time to a string by using the current or specified locale.
Name | Type | Description |
---|---|---|
locales? | LocalesArgument | A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. |
options? | DateTimeFormatOptions | An object that contains one or more properties that specify comparison options. |
string
Date.toLocaleString
Date.toLocaleString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es2020.date.d.ts:27
▸ toLocaleTimeString(): string
Returns a time as a string value appropriate to the host environment's current locale.
string
Date.toLocaleTimeString
Date.toLocaleTimeString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:775
▸ toLocaleTimeString(locales?
, options?
): string
Converts a time to a string by using the current or specified locale.
Name | Type | Description |
---|---|---|
locales? | string | string [] | A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. |
options? | DateTimeFormatOptions | An object that contains one or more properties that specify comparison options. |
string
Date.toLocaleTimeString
Date.toLocaleTimeString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:4553
▸ toLocaleTimeString(locales?
, options?
): string
Converts a time to a string by using the current or specified locale.
Name | Type | Description |
---|---|---|
locales? | LocalesArgument | A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. |
options? | DateTimeFormatOptions | An object that contains one or more properties that specify comparison options. |
string
Date.toLocaleTimeString
Date.toLocaleTimeString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es2020.date.d.ts:41
▸ toString(): string
Returns a string representation of a date. The format of the string depends on the locale.
string
Date.toString
Date.toString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:765
▸ toTai64(): string
Returns the Tai64 timestamp.
string
the Tai64 timestamp
packages/utils/src/utils/date-time.ts:139
▸ toTimeString(): string
Returns a time as a string value.
string
Date.toTimeString
Date.toTimeString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:769
▸ toUTCString(): string
Returns a date converted to a string using Universal Coordinated Time (UTC).
string
Date.toUTCString
Date.toUTCString
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:909
▸ toUnixMilliseconds(): number
number
the unix milliseconds timestamp
packages/utils/src/utils/date-time.ts:146
▸ toUnixSeconds(): number
number
the unix seconds timestamp
packages/utils/src/utils/date-time.ts:153
▸ valueOf(): number
Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
number
Date.valueOf
Date.valueOf
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:777
▸ UTC(year
, monthIndex
, date?
, hours?
, minutes?
, seconds?
, ms?
): number
Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date.
Name | Type | Description |
---|---|---|
year | number | The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year. |
monthIndex | number | The month as a number between 0 and 11 (January to December). |
date? | number | The date as a number between 1 and 31. |
hours? | number | Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour. |
minutes? | number | Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes. |
seconds? | number | Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds. |
ms? | number | A number from 0 to 999 that specifies the milliseconds. |
number
Date.UTC
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:947
▸ UTC(year
, monthIndex?
, date?
, hours?
, minutes?
, seconds?
, ms?
): number
Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date.
Name | Type | Description |
---|---|---|
year | number | The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year. |
monthIndex? | number | The month as a number between 0 and 11 (January to December). |
date? | number | The date as a number between 1 and 31. |
hours? | number | Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour. |
minutes? | number | Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes. |
seconds? | number | Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds. |
ms? | number | A number from 0 to 999 that specifies the milliseconds. |
number
Date.UTC
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es2017.date.d.ts:30
▸ fromTai64(tai64
): DateTime
Generates a new DateTime instance from a Tai64 timestamp.
Name | Type | Description |
---|---|---|
tai64 | string | Tai64 timestamp |
a new DateTime instance
packages/utils/src/utils/date-time.ts:107
▸ fromUnixMilliseconds(unixMilliseconds
): DateTime
Name | Type | Description |
---|---|---|
unixMilliseconds | number | unix milliseconds timestamp |
a new DateTime instance
packages/utils/src/utils/date-time.ts:115
▸ fromUnixSeconds(unixSeconds
): DateTime
Name | Type | Description |
---|---|---|
unixSeconds | number | unix seconds timestamp |
a new DateTime instance
packages/utils/src/utils/date-time.ts:123
▸ now(): number
Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
number
Date.now
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:949
▸ parse(s
): number
Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970.
Name | Type | Description |
---|---|---|
s | string | A date string |
number
Date.parse
node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/lib.es5.d.ts:936