1. Date object
One object every day, let's take a look at the Date object today. Compared with time, everyone must be familiar with it. It should encounter such time special effects in many places in the website. Nutraitter knows new, today we will recall the Date object.
Let's first look at his definition:
dateobj = new date ()
dateobj = new date (dateval)
dateobj = new date (year, month, date [, house [, minutes [, seconds [, ms]]])])])])]
Must be options. If it is a digital value, Dateval indicates the milliseconds of the specified date and the global standard time at midnight on January 1, 1970. If it is a string, the dateval is analyzed in accordance with the rules in the PARSE method. Dateval parameters can also be the VT_DATE value returned from some ActiveX® objects. Must be options. Full years, for example, 1976 (rather than 76). Must be options. The monthly indicated is an integer between 0 and 11 (January to December). Must be options. The date is an integer between 1 and 31. Options. It means milliseconds, from 0 to 999 integer.
The Date object is preserved in milliseconds to represent a certain time period. If the value of a parameter is greater than its range or negative, the other values stored will be adjusted accordingly. For example, if 150 seconds are specified, 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 the parameters are not passed to the Date object, it will be initialized to the current time (UTC). It must be assigned to it before being able to use this object.
The date range that DATE objects can be represented are equivalent to 285,616 each after January 1, 1970.
Date objects have two static methods that can be called without creating Date objects. They are PARSE and UTC.
There are many methods of the Date object, and it is very simple to list here. OK, SEE NEXT!
Special attention:
************************************************* **************
var mydate = new date (2006,11,23);
Alert ("year ="+mydate.getyear ()+"****** month ="+mydate.getmonth ()+"*********"+mydate.getdate ());
After running, the result is year = 2006 ****** month = 11 ********** day = 23
************************************************* **************
The display in this way is normal. When the month passed in by New Date is 12, there are problems.
************************************************* **************
var mydate = new date (2006,12,23);
Alert ("year ="+mydate.getyear ()+"****** month ="+mydate.getmonth ()+"*********"+mydate.getdate ());
After running, the result is year = 2007 ****** month = 0 ********** day = 23
************************************************* **************
Very wondering. Finally, check the information to know that the value of the parameter Month is 0 ~ 11, and it cannot be passed into the value of 12. The solution is to make MONTH-1 when it is passed, and then +1 when it is taken outside. I don't know who has a better way.
like:
Var date = New Date (2010, 0-1,15); // Here 0 represents January, and the minus 1 will become 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 ());
The parameter is the format of the string, such as: 2010/1/6
Example:
var txtDepartureDate = '2010-1-6'
Alert (txtDeparturedate.replace (/-/g, '/')); // Use regularly to replace all '-' to //
var date = new date (txtDepaparturedate.replace (/-/g, '/'));