Learning Essentials:
Date Object
Convert a Date object to a string
Converts a date and time in a Date object to a string
Date in Date Object
Time in a Date object
Set a date in a Date object
Set the time in a Date object
Milliseconds-related methods
One, Date object
There are no date-type data types in JavaScript, but a Date object is available to manipulate the date and time.
Creation of date objects:
New Date ();
Ii. Converting a Date object to a string
You can use the following 4 methods to convert a Date object to a string:
Date.tostring ();//When converting a Date object to a string, the local time is used
Date.tolocalstring ();//Converts a Date object to a string, using local time, showing the format of the local date
Date.toutcstring ();//When you convert a Date object to a string, the world time is used.
Date.togmtstring ();//The GMT time is used when converting a Date object to a string, but it is disabled and is generally replaced with the toUTCString () method.
Iii. converting dates and times in date objects to strings
Date.todatestring ();//Convert the date part to a string, local time
Date.tolocaldatestring ();//Converts the date part to a string, using the local time, which shows the format of the local date
Date.totimestring ();//Convert the time part to a string, local time
Date.tolocaltimestring (); Converts the time part to a string, using the local time, which shows the format of the local date
Iv. Dates in date objects
Date.getyear ();//Gets the year but is not recommended for use.
Date.getfullyear ();//Gets the year, in four-digit numbers, and recommends using
Date.getmonth ();//Gets the month, the value is 0-11, January is 0, February is 1 ...
Date.getdate ();//Gets the number of days, that is, one day in one months
Date.getday ();//Gets the day of the week, the value is 0-6, Sunday is 0 ...
V. Time in a Date object
Date.gethours ();//Return Hour section
Date.getminutes ();//Return minute part
Date.getseconds ();//Return second part
Date.getmilliseconds ();//returns the millisecond part
Date.gettime ();//Returns the number of milliseconds between the time in the Date object and the January 1, 1970 0:0 0 seconds
Date.gettimezoneoffset ();//Returns the number of times in seconds between the time in the Date object and UTC.
Vi. Setting the date in the Date object
Date.setyear (year);//Not recommended
Date.setfullyear (year,month,day);//year four digits; month:0-11, this parameter can be omitted; day:1-31, this parameter can be omitted
Date.setmonth (month,day);//month:0-11;day:1-31, this parameter can be omitted
Date.getdate (day);//day:1-31
Vii. setting the time in a Date object
Date.gethours (hours,minutes,seconds,milliseconds);//hours:0-23,minutes:0-59, can be omitted, seconds:0-59, can be omitted milliseconds:0 -999, can be omitted
Date.getminutes (minutes,seconds,milliseconds);//minutes:0-59,seconds:0-59, can omit milliseconds:0-999, can omit
Date.getseconds (seconds,milliseconds);//seconds:0-59,milliseconds:0-999, can be omitted
Date.getmilliseconds (milliseconds);//,milliseconds:0-999
Viii. methods related to milliseconds
Date.settime (millisecinds); milliseconds represents the number of milliseconds between the time that is set and the January 1, 1970 0:0 0 seconds
Date.valueof (); Returns the number of milliseconds between the time in the Date object and the January 1, 1970 0:0 0 seconds
Date.parse (str); Returns the number of milliseconds between the time that the str parameter represents and the January 1, 1970 0:0 0 seconds
Date. UTC (year,month,day,hours,minutes,seconds,milliseconds); Converts the date represented by the parameter to the number of milliseconds between January 1, 1970 0:0 and 0 seconds
Transfer from http://www.cnblogs.com/LiuJL/p/5563606.html
Object from the date of JavaScript (GO)