JavaScript Learning Notes (vi) Date dates Type _ basics

Source: Internet
Author: User
Tags date1
1. Create Date objects
Copy Code code as follows:

var now = new Date (); Get current system date and time
var somedate = new Date (Date.parse ("may 25,2012"));
var somedate = new Date ("may 25,2012"); Same as on
var somedate = new Date (DATE.UTC (2010,0)); GMT time January 1, 2010 0 o'clock in the morning
var somedate = new Date (2010,0); Same as on
var somedate = new Date (DATE.UTC (2010,4,5,17,55,55)); GMT Time May 2010 5:55:55, month and time with 0 base, 0 for month
var somedate = new Date (2010,4,5,17,55,55); Same as on

Date.parse () and DATE.UTC () return the number of milliseconds for the corresponding date, the DATE.UTC () parameters are: year, month, day, hour, minute, second, millisecond. At least 2 years and a month. The month and the time are based on 0.
2. Comparison of dates
Copy Code code as follows:

var date1 = new Date (2007,0,1);
var date2 = new Date (2007,1,1);
alert (DATE1>DATE2); False
alert (DATE1<DATE2); True

3. Date format method and get Set Date method
Copy Code code as follows:

View Code
todatestring ()
totimestring ()
toLocaleDateString () As of January 1, 2007
toLocaleTimeString ()//As 13:55:55
toUTCString ()
GetTime ()//return the number of milliseconds
SetTime ()
getFullYear ()//Get year, such as 2007
setFullYear ()
GetMonth ()//Get month, 0 for January
setmonth ()//Set month, 0 for January, more than 11 year added
GetDate ()///Get days in Date
Setdate ()//Set number of days, more than 31 added month
Getday ()//Get week, 0 for Sunday, 6 for Saturday
GetHours ()//Get hour, 0~23 sethours ()//Set hours, 0~23
getminutes ()//Get minutes, 0~59
Setminutes ()/Set minutes, 0~59
Getseconds ()//Get seconds, 0~59 setseconds ()//Set the number of seconds, 0~59
getmilliseconds ()//Get milliseconds
setmilliseconds ()//set milliseconds
Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.