JS Date is easy to use

  • 2020-03-26 21:32:26
  • OfStack

The JS Date object is used to handle dates and times.
Syntax for creating Date objects:
Var myDate = new Date ()
The Date object automatically saves the current Date and time as its initial value.
There are five parameter forms as follows:
 
new Date("month dd,yyyy hh:mm:ss"); 
new Date("month dd,yyyy"); 
new Date(yyyy,mth,dd,hh,mm,ss); 
new Date(yyyy,mth,dd); 
new Date(ms); 

Note that in the last form, the parameter represents the number of milliseconds between the time you need to create and the GMT of January 1, 1970. The meanings of various functions are as follows:

Month: December, December, December, December, December, December

MTH: an integer for months, from 0 to 11(January to December)

Dd: represents the days of the month, from 1 to 31

Yyyy: the year represented by four digits

Hh: hours, from 0 (midnight) to 23 (11 PM)

Mm: minutes, integers from 0 to 59

Ss: number of seconds, integers from 0 to 59

Ms: a number of milliseconds, an integer greater than or equal to 0

Such as:
 
new Date("January 12,2006 22:19:35"); 
new Date("January 12,2006"); 
new Date(2006,0,12,22,19,35); 
new Date(2006,0,12); 
new Date(1137075575000); 

Date() returns the Date and time of the day.
GetDate () returns a day of the month (1-31) from the Date object.
GetDay () returns a day of the week (0 to 6) from the Date object.
GetMonth () returns months (0-11) from the Date object.
GetFullYear () returns the year with four digits from the Date object.
Use the getFullYear() method instead of getYear().
GetHours () returns the hours (0 ~ 23) of the Date object.
GetMinutes () returns the minutes of the Date object (0 ~ 59).
GetSeconds () returns the number of seconds (0-59) of the Date object.
GetMilliseconds () returns the Date object in milliseconds (0 to 999).
GetTime () returns the number of milliseconds since January 1, 1970.
GetTimezoneOffset () returns the minute difference between local time and Greenwich mean time (GMT).
GetUTCDate () returns a day in the month (1-31) from a Date object based on universal time.
GetUTCDay () returns the day of the week (0-6) from the Date object in universal time.
GetUTCMonth () returns months (0-11) from the Date object based on universal time.
GetUTCFullYear () returns a four-digit year from a Date object based on universal time.
GetUTCHours () returns the number of hours (0 to 23) of the Date object based on universal time.
GetUTCMinutes () returns the minutes (0-59) of the Date object based on universal time.
GetUTCSeconds () returns the number of seconds (0-59) of a Date object in universal time.
GetUTCMilliseconds () returns the number of milliseconds (0 to 999) of the Date object based on world time.
Parse () returns the number of milliseconds between midnight on January 1, 1970, and the specified date (string).
SetDate () sets the Date of a month in the Date object (1-31).
SetMonth () sets the month (0 ~ 11) in the Date object.
SetFullYear () sets the year (four digits) in the Date object.
Use the setFullYear() method instead for setYear().
SetHours () sets the hours (0 ~ 23) in the Date object.
SetMinutes () sets the minutes (0 ~ 59) in the Date object.
SetSeconds () sets the seconds in the Date object (0-59).
SetMilliseconds () sets the milliseconds in the Date object (0 to 999).
SetTime () sets the Date object in milliseconds.
SetUTCDate () sets the day (1-31) of the month in the Date object based on universal time.
SetUTCMonth () sets the months (0-11) in the Date object based on universal time.
SetUTCFullYear () sets the year (four digits) in the Date object based on universal time.
SetUTCHours () sets the hours (0 ~ 23) in the Date object based on universal time.
SetUTCMinutes () sets the minutes (0-59) in the Date object based on universal time.
SetUTCSeconds () sets the seconds (0-59) in the Date object based on universal time.
SetUTCMilliseconds () sets the milliseconds (0 to 999) in the Date object based on world time.
ToSource () returns the source code for the object.
ToString () converts the Date object to a string.
ToTimeString () converts the time part of the Date object to a string.
ToDateString () converts the Date part of the Date object to a string.
ToGMTString () use the toUTCString() method instead.
ToUTCString () converts the Date object to a string based on universal time.
ToLocaleString () converts the Date object to a string based on the local time format.
ToLocaleTimeString () converts the time part of the Date object to a string based on the local time format.
ToLocaleDateString () converts the Date part of the Date object to a string based on the local time format.
UTC() returns the number of milliseconds from January 1, 1997 to the specified date according to universal time.
ValueOf () returns the original valueOf the Date object.
/ / var objDate = new Date ([] the arguments list);

Related articles: