This article is mainly on the date of JS and access to the system of the current time is introduced, the need for friends can come to the reference, I hope to be helpful to everyone
One, date objects a day object, today to see the Date object, relative to time everyone must be very familiar with, should be in the site before many places will encounter such a time effect. Let's take a moment to recall the date object today. Let's take a look at his definition first: Dateobj = new Date () Dateobj = new Date (dateval) dateobj = new Date (year, month, date[, hours[, minute s[, Seconds[,ms]] required options. In the case of a numeric value, Dateval represents the number of milliseconds between the specified date and the global standard Time between midnight January 1, 1970. If it is a string, the dateval is parsed according to the rules in the parse method. The Dateval parameter can also be a vt_date value returned from some ActiveX® objects. Required option. Full year, for example, 1976 (instead of 76). Required option. Represents the month, which is an integer from 0 to 11 (January to December). Required option. Represents a date, which is an integer from 1 to 31. Options available. Represents milliseconds, an integer from 0 to 999. The Date object holds a specific time period in milliseconds. If the value of a parameter is greater than its range or is negative, the other stored values are adjusted accordingly. For example, if you specify 150 seconds, JScript redefines the number to 2 minutes and 30 seconds. If the number is NaN, the object does not represent a specific time period. If an argument is not passed to the Date object, it is initialized to the current time (UTC). You must assign a value to the object before it can be used. The date range that the Date object can represent is approximately equal to 285,616 years before and after January 1, 1970. The Date object has two static methods that can be invoked without creating a Date object. They are parse and UTC. There are a lot of methods for date objects, and it's simply not listed here, Ok,see next! Special Note: ************************************************************** var mydate = new Date ( 2006,11,23); Alert ("Year=" +mydate.getyear () + "******mOnth= "+mydate.getmonth () +" ********day= "+mydate.getdate ()); The result of operation is year=2006 ******month=11********day=23 ***************************************************** This display is normal, when the new date is passed in the month of 12, the problem arises. ************************************************************** var mydate = new Date (2006,12,23); Alert ("Year=" +mydate.getyear () + "******month=" +mydate.getmonth () + "********day=" +mydate.getdate ()); The result of operation is year=2007 ******month=0********day=23 ****************************************************** was wondering about one thing. Finally check the data that month this parameter's value is 0~11, cannot pass in 12 of this value. The solution is to put the month-1 when the value is passed, and then +1 when it is taken out of the way. I don't know who else has a better way. such as: var date=new date (2010,0-1,15); Here 0 represents January, minus 1 becomes December alert (date.getyear () + "," + (Date.getmonth () +1) + "," +date.getdate ()); VAR date=new date (2010,12-1,15); alert (Date.getyear () + "," + (Date.getmonth () +1) + "," +date.getdate ()); parameter is a format for strings such as: 2010/1/6 Example: Var txtdeparturedate= ' 2010-1-6 ' AlerT (Txtdeparturedate.replace (/-/g, '/')); Use positive to replace '-' all/var date = new Date (Txtdeparturedate.replace (/-/g, '/'));