Date Type:
Description: JS provides a date type to handle time and date, a date type built in some columns Gets or sets a method of datetime information, date type initialization parameters are saved with a timestamp
Create Date object, default current time object, support initialization, but must be able to parse var newdate = new Date () Console.log (newdate) var newdate = new Date (' 8/30/2016 ') Console.log (newdate) var newdate = new Date (' August ') Console.log (newdate) var newdate = new Date (' August 30 2016 1 5:38:00 GMT-070 ')
Note: The default parameter for date object initialization is a timestamp, and of course the string is supported, but must be Date.parse (string) to resolve to a timestamp, since any object has a public. toString ()/.tolocalstring ()/.valueof () method, so the default printing time Date object is automatically converted to a string, which defaults to the current time, if
Format Date:
Description: The Date object also has some specialized methods for converting dates to strings
Format date var newdate = new Date (' 8/30/2016 ')//-todatestring (), displayed in a specific format English week, English month, day, year Console.log (Newdate.todatestring () //-toTimeString (), displayed in a specific format: minutes: Seconds time Zone (time zone description) Console.log (newdate.totimestring ())//-tolocaledatestring (), to specific Format display year/month/day Console.log (newdate.tolocaledatestring ())//-tolocaletimestring (), display in a specific format morning | pm: minutes: Seconds Console.log ( Newdate.tolocaletimestring ()//-toutcstring (), in a specific format English week, day English month: minutes: seconds Time Zone Console.log (newdate.toutcstring ())
Component methods:
Description: The component method is set for us to obtain a separate time/date value for each of these methods, with UTC, with or without UTC, the date value in the absence of a time zone bias
Gets the number of milliseconds of the date, and valueof returns a consistent var newdate = new date (' 8/30/2016 ') Console.log ( Newdate.gettime ())// sets the date in milliseconds and changes the date object throughout the date Console.log (Newdate.settime (1472486400000))// Get year four-bit year Console.log (Newdate.getfullyear ())// set four-bit year, return the number of milliseconds Console.log (newdate.setfullyear)// Get month, starting from 0 Console.log (Newdate.getmonth ())// set month, starting from 0 console.log (Newdate.setmonth (7))// Get Date Console.log (Newdate.getdate ())// set the date, return the number of milliseconds Console.log (Newdate.setdate ())// get day of the week, 0 for Sunday, 6 means Saturday Console.log (Newdate.getday ())// acquired when Console.log (Newdate.gethours ())// is set Console.log ( Newdate.sethours ()// Get minutes Console.log (Newdate.getminutes ())// set minutes Console.log (Newdate.setminutes ( ))// Get Seconds Console.log (Newdate.getseconds ())// set seconds Console.log (newdate.setseconds)// Get Millisecond Console.log (Newdate.getmilliseconds ())// set milliseconds Console.log (Newdate.setmilliseconds ())// Gets the number of minutes between local time and UTC time Console.log (Newdate.gettimezoneoffset ())
Note: The above method except getTimezoneOffset (), the other has the UTC function, indicates the world coordinated time, if is UTC time, the display time needs to convert to the local time, otherwise has the difference
Type method:
Creates a Date object, the default current time object, which supports initialization, but must be able to parse var newdate = new Date () Console.log (newdate)//Parse Date string – Date class method. Parse (), Parse failed returns false * Format one: ' Month/day/year ' 8/30/2016 * format two: ' English month name Day ' August 30, 2016 * format three: ' English week English month name: minutes: Seconds time zone ' * *///try to parse the date format console . log (Date.parse (' 8/30/2016 '))//Implicit call Date.parse Parse generates date object Console.log (new date (' 8/30/2016 '))// resolves to UTC time and then generates DateTime object Console.log (new Date (Date.parse (' 8/30/2016 '))//generates UTC timestamp-date class method. UTC () Console.log (new Date ( DATE.UTC (2016, 8, 30, 14, 39, 16)))
This article is from the "ζ Automated operation and maintenance development Road ζ" blog, please be sure to keep this source http://xmdevops.blog.51cto.com/11144840/1846129
Site front-end _javascript.0009.javascript date Time