JS Date function in the use of parameters
- 2020-03-30 01:10:20
- OfStack
To create a date object, use the following:
Of course, no arguments are passed in the function to indicate that the object now automatically gets the current time.
If you want to create an object with a custom time, pass the Date() argument. This parameter, however, must be the number of milliseconds (from midnight UTC on January 1, 1970 to the custom time).
We can use date.parse () and date.utc () to get the number of milliseconds of the custom time.
Date.parse() receives a string parameter representing a Date, such as "May 25,2013","6/13/2013", etc. The format supported varies from locale to locale.
Date.utc () receives parameters such as year, number of months starting from 0 (0-11), day of the month (1-31), hour tree (0-23), minute, second, and millisecond respectively.
If we now want to define a Date object for December 12, 2013, we can use date.parse () :
Var mydate = new Date (the Date the parse (" 12/12/2013 ")),
If so:
Var mydate=new Date("12/12/2013") automatically calls date.parse () when constructing a Date to convert the Date string to a number of milliseconds.
Date.utc () can also be used:
Var mydate=new Date(date.utc (2013,11,12)// note that month subscripts start at 0 and day subscripts start at 1
If so:
Var mydate=new Date(2013,11,12), similar to the parse constructor above, will automatically call date.utc () when constructing a Date object. But notice that var mydate=new Date(date.utc (2013,11,12) gets the GMT time, while var mydate=new Date(2013,11,12) gets the local time based on the system Settings.
var now=new Date()
Of course, no arguments are passed in the function to indicate that the object now automatically gets the current time.
If you want to create an object with a custom time, pass the Date() argument. This parameter, however, must be the number of milliseconds (from midnight UTC on January 1, 1970 to the custom time).
We can use date.parse () and date.utc () to get the number of milliseconds of the custom time.
Date.parse() receives a string parameter representing a Date, such as "May 25,2013","6/13/2013", etc. The format supported varies from locale to locale.
Date.utc () receives parameters such as year, number of months starting from 0 (0-11), day of the month (1-31), hour tree (0-23), minute, second, and millisecond respectively.
If we now want to define a Date object for December 12, 2013, we can use date.parse () :
Var mydate = new Date (the Date the parse (" 12/12/2013 ")),
If so:
Var mydate=new Date("12/12/2013") automatically calls date.parse () when constructing a Date to convert the Date string to a number of milliseconds.
Date.utc () can also be used:
Var mydate=new Date(date.utc (2013,11,12)// note that month subscripts start at 0 and day subscripts start at 1
If so:
Var mydate=new Date(2013,11,12), similar to the parse constructor above, will automatically call date.utc () when constructing a Date object. But notice that var mydate=new Date(date.utc (2013,11,12) gets the GMT time, while var mydate=new Date(2013,11,12) gets the local time based on the system Settings.