A: What is the Date object?
The Date object is used to process dates and times.
Two: Date creation syntax
1. Direct access to the current time is standard Time
var date = new Date ()
Console.log (date)//tue Dec 23:09:42 gmt+0800 (China Standard Time)
Note: The Date object automatically saves the current date and time as its initial value.
2. Specify time to change to standard time
var date1 = new Date ("January 12,2006 22:19:35")
Console.log (date1)//thu Jan 2006 22:19:35 gmt+0800 (China Standard Time)
Several of the following formats are available:
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);
Three: Common Object methods
Date.getfullyear ()//2017 returns the year as a four-digit number from a Date object
Date.getmonth ()//11 returns the month from the Date object (0 ~ 11)
Date.getday ()//2 returns one day of the week from a Date object (0 ~ 6)
Date.getdate ()//12 returns one day in one months from a Date object (1 ~ 31)
Date.gethours ()//23 returns the hour of the date object (0 ~ 23)
Date.getminutes ()//30 returns the minute of the Date object (0 ~ 59)
Date.getseconds ()//54 returns the number of seconds of the date object (0 ~ 59)
Date.getmilliseconds () returns the milliseconds of the Date object (0 ~ 999)
Date.gettime () returns the number of milliseconds since January 1, 1970
Four: each case conversion
1. var time = "2017-12-12" converted to millisecond timestamp
New Date (Time.replace (/-/g, "/")). GetTime ()//1513008000000
2. var time = 1513008000000 converted to "2017-12-12"
Note: Time cannot be a string if number
var date = new Date (time)
var year1 = Date2.getfullyear ()
var month = Date2.getmonth ()
var today = Date2.getdate ()
var Time1 = year1 + "-" + month + "-" + Today
The use of Date objects in JS