JavaScript time functions
JavaScript provides a Date object for calculations of time and date.
The Date object has several constructors:
New Date ()//Current time
Number of milliseconds for new Date (milliseconds)//distance start January 1, 1970
The date and time represented by the new date (datestring)//String. This string can be converted using date.parse () such as "Jannuary 1, 1998 20:13:15"
New Date (year, month, day, hours, minutes, seconds, microseconds)//time value, which can be written without all, not written, defaults to 0
When used, create a Date object, such as:
Dateobj=new Date ();
Then call the function, such as
Year=dateobj.getfullyear ()//Get year value
The following is a list of functions.
To get the class function:
GetDate () function--Return days (1-31)
Getday () function--Returns the number of weeks (0-6)
getFullYear () function--returns four-digit years
GetHours () function--Returns the number of hours (0-23)
Getmilliseconds () function--Returns the number of milliseconds (0-999)
Getminutes () function--Returns the number of minutes (0-59)
GetMonth () function--Returns the number of months (0-11)
Getseconds () function--Number of seconds returned (0-59)
GetTime () function--Returns the timestamp notation (in milliseconds)
GetYear () function--return year (real year minus 1900)
To set a class function:
(The following functions return the number of milliseconds between the date objects from midnight January 1, 1970)
Setdate () function--set the day of the month
setFullYear () function--set year, month, and day
Sethours () function--set hours, minutes, seconds, and milliseconds
Setmilliseconds () function--set the number of milliseconds
Setminutes () function--set minutes, seconds, milliseconds
Setmonth () function--Set month, day
Setseconds () function--set the day of the month
SetTime () function--use milliseconds to set the Date object
Setyear () function--set year (real year minus 1900)
Convert Display class function:
Tolocalstring () function--Returns a localized string representation
tolocaledatestring Function--Returns the localized string for the date part
tolocaletimestring function--a localized string that returns the time part
Relative to the local output, there are:
ToString ()
toDateString ()
toTimeString ()
The difference is that the former is based on different machines that have different local language formats, and the latter is the internal representation format
Date resolution class function
Date.parse () function--parses a string of dates and returns the number of milliseconds between midnight of January 1, 1970
Time zone related parts see JavaScript time zone functions