DateTime

Represents an instant in time

Constructor
DateTime()

Construct a DateTime object that is set to the current date and time, expressed as the Coordinated Universal Time (UTC) time


DateTime(dateTime: DateTime)

Construct a DateTime object from another DateTime object

Parameters
dateTime another DateTime to copy values from

DateTime(year: number, month: number = 0, day: number = 0, hour: number = 0, minute: number = 0, second: number = 0, millis: number = 0)

Construct a DateTime object to the specified year, month, day, hour, minute, second, millisecond, and Coordinated Universal Time (UTC)

Parameters
year The year component
month The month component
day The day component
hour The hour component
minute The minute component
second The second component
millis The millisecond component
Static Methods
parse
static DateTime parse(s: string)

Converts the string representation of a date and time to its DateTime equivalent

Parameters
s string representation of a date and time in ISO8601 standard
Return
DateTime The DateTime
fromUnixMillis
static DateTime fromUnixMillis(millis: number)

Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z in Coordinated Universal Time (UTC)

Parameters
millis The milliseconds from 1970-01-01T00:00:00Z
Return
DateTime The DateTime
timeZoneOffset
static number timeZoneOffset()

Gets the millisecond offset to add to UTC to get local time

Return
number The millisecond offset to add to UTC to get local time
Methods
date
DateTime date()

Gets the date component of this instance (Year, month, day is unchanged. Hour, minute, second, millisecond is set to 0)

Return
DateTime The date component
year
number year()

Gets the year component of this instance

Return
number The year component
month
number month()

Gets the month component of this instance

Return
number The month component
day
number day()

Gets the day of month component of this instance

Return
number The day of month component
dayOfWeek
number dayOfWeek()

Gets the day of week component of this instance

Return
number The day of week component
dayOfYear
number dayOfYear()

Gets the day of year component of this instance

Return
number The day of year component
hour
number hour()

Gets the hour component of this instance

Return
number The hour component
minute
number minute()

Gets the minute component of this instance

Return
number The minute component
second
number second()

Gets the second component of this instance

Return
number The second component
millis
number millis()

Gets the millisecond component of this instance

Return
number The millisecond component
totalMillis
number totalMillis()

Gets the milliseconds of the datetime instant from the epoch of 1970-01-01T00:00:00Z

Return
number The milliseconds from the epoch of 1970-01-01T00:00:00Z
add
DateTime add(timeSpan: TimeSpan)

Returns a copy of this datetime with the specified timespan added

Parameters
timeSpan The timespan to add to this one
Return
DateTime A copy of this datetime with the timespan added
addYears
DateTime addYears(years: number)

Returns a copy of this datetime plus the specified number of years

Parameters
years The amount of years to add, may be negative
Return
DateTime The new datetime plus the increased years
addMonths
DateTime addMonths(months: number)

Returns a copy of this datetime plus the specified number of months

Parameters
months The amount of months to add, may be negative
Return
DateTime The new datetime plus the increased months
addDays
DateTime addDays(days: number)

Returns a copy of this datetime plus the specified number of days

Parameters
days The amount of days to add, may be negative
Return
DateTime The new datetime plus the increased days
addHours
DateTime addHours(hours: number)

Returns a copy of this datetime plus the specified number of hours

Parameters
hours The amount of hours to add, may be negative
Return
DateTime The new datetime plus the increased hours
addMinutes
DateTime addMinutes(minutes: number)

Returns a copy of this datetime plus the specified number of minutes

Parameters
minutes The amount of minutes to add, may be negative
Return
DateTime The new datetime plus the increased minutes
addSeconds
DateTime addSeconds(seconds: number)

Returns a copy of this datetime plus the specified number of seconds

Parameters
seconds The amount of seconds to add, may be negative
Return
DateTime The new datetime plus the increased seconds
addMillis
DateTime addMillis(milliseconds: number)

Returns a copy of this datetime plus the specified number of milliseconds

Parameters
milliseconds The amount of milliseconds to add, may be negative
Return
DateTime The new datetime plus the increased milliseconds
sub
DateTime sub(timeSpan: TimeSpan)

Returns a copy of this datetime with the specified timespan subtracted

Parameters
timeSpan The timespan to subtract to this one
Return
DateTime A copy of this datetime with the timespan subtracted
sub
TimeSpan sub(dateTime: DateTime)

Returns a new TimeSpan object whose value is the difference between the two DateTime

Parameters
dateTime The DateTime to subtract to this one
Return
TimeSpan A new TimeSpan object whose value is the difference between the two DateTime
format
string format(pattern: string)

Output the instant using the specified format pattern

Parameters
pattern The pattern specification, null means use ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ)
Return
string The formatted string, not null

© 2024 - Macrorify by KoK-CODE