To create a date object, you can use the following method:
Copy codeThe Code is as follows:
Var now = new Date ()
Of course, the function does not pass any parameters, indicating that the object now automatically obtains the current time.
If you want to create a custom time object, you must pass the Date () parameter. This parameter must be in milliseconds (the number of milliseconds from midnight on January 1, January 1, 1970 to the custom time ).
We can use Date. parse () and Date. UTC () to get the number of milliseconds for the custom time.
Date. parse () receives a string parameter that represents the Date, for example, "May 25, 2013", "6/13/2013", and other formats. The supported formats vary by region.
And Date. the parameters received in UTC () are the year, the number of months starting from 0 (0-11), and the day of the month (1-31) the hour tree (0-23), minute, second, and millisecond. The year and the number of months are required. The default value of other parameters is 0.
If you want to define a Date object for January 1, December 12, 2013, you can use Date. parse ():
Var mydate = new Date (Date. parse ("12/12/2013 ")),
If so:
Var mydate = new Date ("12/12/2013"), when constructing a Date, Date. parse () is automatically called to convert the Date string to the number of milliseconds.
You can also use Date. UTC ():
Var mydate = new Date (Date. UTC (, 12) // note that the subscripts of the Month start from 0, and The subscripts of the day start from 1.
If so:
Var mydate = new Date (, 12), similar to the preceding parse constructor, Date is automatically called when constructing a Date object. UTC (). If the first parameter is a numeric value, it is treated as the year, and the second parameter is month ...... note that the former var mydate = new Date (Date. UTC (, 12) obtains the GMT time, while the latter var mydate = new Date (, 12) obtains the local time based on the system settings.