Represents an instant in time
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 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 |
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 |
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 |
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 |
number year()
Gets the year component of this instance
| Return | |
| number | The year component |
number month()
Gets the month component of this instance
| Return | |
| number | The month component |
number day()
Gets the day of month component of this instance
| Return | |
| number | The day of month component |
number dayOfWeek()
Gets the day of week component of this instance
| Return | |
| number | The day of week component |
number dayOfYear()
Gets the day of year component of this instance
| Return | |
| number | The day of year component |
number hour()
Gets the hour component of this instance
| Return | |
| number | The hour component |
number minute()
Gets the minute component of this instance
| Return | |
| number | The minute component |
number second()
Gets the second component of this instance
| Return | |
| number | The second component |
number millis()
Gets the millisecond component of this instance
| Return | |
| number | The millisecond component |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
© 2025 - Macrorify by KoK-CODE