First, create a date example
1. The methods and properties of the date class are very static, therefore, the application date property and the method before. You must create an instance of the date class.
var date = new Date (); Creates an instance with the current date and time.
var date = new Date (value); Value is a required option, assuming a numeric value. Value represents the number of milliseconds between the specified date and midnight 1970.1.1. The assumption is a string. Value is parsed according to the rules in the parse () method.
The global date () function is finished with the same function as new date (value)
var date = new Date (Year[,month[,date[,hour[,minute[,second[,millisecond]] []]); The parameter descriptions are as follows:
Second, parse the date string using the Parse () method
The Date.parse (datestring) method resolves a datetime string and returns the number of milliseconds between midnight of 1970/1/1 and the date time. DateString required. A string that represents the date and time of the format, such as Jan 5,1996 08:47:00.
Parsing rules:
A short date can use "/" or "-" as the date separator, but must be expressed in the format of a month/day/year, such as "7/20/96".
The year, month, and day of a long date in the form of "July 10 1995" can be arranged in whatever order. The year value can be represented by a 2-digit number, or by a 4-digit number. Suppose you use a 2-digit number to represent the year. Then the year must be greater than or equal to 70.
Whatever text in parentheses is considered a gaze. These parentheses can be used in a nested set.
Commas and spaces are treated as delimiters. Agree to use multiple separators.
The name of the month and day must have two or more than two characters. Assuming that the two-character name is not unique, the name is parsed to the last qualifying month or day. For example, the "Ju" was interpreted as July rather than June.
On the date provided, the specified value is ignored if the value of the day of the week specified does not match the value of the day of the week determined by the remainder of the date.
-
For example, although November 9, 1996 is actually Friday. "Tuesday November 9 1996" can also be accepted and parsed. However, the result Date object includes "Friday November 9 1996".
- JScript handles all of the standard time zones, as well as global standard times (UTC) and Greenwich Mean Time (GMT).
- Hours, minutes, and seconds are separated by colons. Although not all of these three items need to be specified. "10:", "10:11", and "10:11:12" are valid.
- Assuming a 24-hour clock is used, it is wrong to specify "PM" for the time after 12 o'clock noon.
-
For example, "23:15 PM" is wrong.
- A string that includes an invalid date is an error. For example, a string that includes two years or two months is wrong.
<script language="javascript" src="date.js"></script>
< script language = "JavaScript" >
var retval = new DateFormat("MM-dd-yyyy HH:mm:ss").format(new Date())
//Time format must be MM DD yyyy HH: mm: SS
document.write(retval)
var d = Date.parse(retval)
document.write(d)
</script>
Third, date class methods
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmta0mzg0mw==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
JavaScript authoritative guide 13th study Note: Date and time of use