Talk about date objects in JavaScript

Source: Internet
Author: User
Tags local time

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

Excerpt from: http://www.itxm.net/a/bianchengyuyan/2016/0613/318.html

Reference: http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html

Talk about date objects in JavaScript

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.