JavaScript
Creates a JavaScript Date instance that represents a single moment in time. Date objects are based on a time value that is the number of milliseconds since 1 January 1970 UTC.
Last updated
Creates a JavaScript Date instance that represents a single moment in time. Date objects are based on a time value that is the number of milliseconds since 1 January 1970 UTC.
Last updated
value
Integer value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC, with leap seconds ignored (Unix Epoch; but consider that most Unix timestamp functions count in seconds).
monthIndex
Integer value representing the month, beginning with 0 for January to 11 for December.
day
Optional. Integer value representing the day of the month.
hours
Optional. Integer value representing the hour of the day.
minutes
Optional. Integer value representing the minute segment of a time.
seconds
Optional. Integer value representing the second segment of a time.
milliseconds
Optional. Integer value representing the millisecond segment of a time.
If no arguments are provided, the constructor creates a JavaScript Date
object for the current date and time according to system settings for timezone offset.
If at least two arguments are supplied, missing arguments are either set to 1 (if the day is missing) or 0 for all others.
The JavaScript date is based on a time value that is milliseconds since midnight January 1, 1970, UTC. A day holds 86,400,000 milliseconds. The JavaScript Date
object range is -100,000,000 days to 100,000,000 days relative to January 1, 1970 UTC.
The JavaScript Date
object provides uniform behavior across platforms. The time value can be passed between systems to create a date that represents the same moment in time.
The JavaScript Date
object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed.
Date.length
is 7. This is the number of arguments handled by the constructor.
Date
objectThe following examples show several ways to create JavaScript dates:
The following examples show how to determine the elapsed time between two JavaScript dates in milliseconds.
Due to the differing lengths of days (due to daylight saving changeover), months and years, expressing elapsed time in units greater than hours, minutes and seconds requires addressing a number of issues and should be thoroughly researched before being attempted.
Uros Durdevic
Note: Where Date
is called as a constructor with more than one argument, the specified arguments represent local time. If UTC is desired, use new Date(
) with the same arguments.
dateString
String value representing a date. The string should be in a format recognised by the method ( and also a ).
year
Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999. See the .
Invoking JavaScript Date
as a function (i.e., without the operator) will return a string representing the current date and time.
Allows the addition of properties to a JavaScript Date
object.Date.length
The value of
In order to create and get dates between the years 0 and 99 the and methods should be used.
Note: In browsers that support the 's high-resolution time feature, can provide more reliable and precise measurements of elapsed time than .
In this case it's important to return only a whole number (so a simple division won't do), and also to only return actually elapsed seconds (that's why this code uses and not ).