#The Date object is a built-in data type in the JavaScript language. Date objects are created using the new Date( ) as shown below.
After you create a Date object, you can operate on it using a variety of methods. Most methods only allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object using local time or UTC (Universal or GMT) time.
You can use any of the following syntax to create a Date object using the Date() constructor -
new Date( )
new Date(milliseconds)
new Date(datestring)
new Date(year,month,date[,hour,minute,second,millisecond ])
The following are parameter descriptions-
-
No parameters - With no parameters, the Date() constructor creates a set of Date objects to the current date and time.
-
Milliseconds− When a numeric argument is passed, it is treated as the internal numeric representation of the date (in milliseconds), as returned by the getTime() method. For example, passing the parameter 5000 creates a date that represents 5 seconds after midnight on 1/1/70.
-
Date string − When a string parameter is passed, it is the string representation of the date, as accepted by the Date.parse() method Format.
-
7 Parameters - To use the last form of the constructor shown above. The following is a description of each parameter -
-
Year- An integer value representing the year. For compatibility (and to avoid Y2K issues), you should always specify the full year; use 1998, not 98.
-
Month - An integer value representing the month, starting from 0 (January) to 11 (December).
-
Date− represents an integer value of the day of the month.
-
Hour− An integer value representing the hour of the day (in 24-hour format).
Minutes − An integer value representing the minute portion of the time reading. -
Seconds − An integer value representing the second segment of the time reading.
-
Milliseconds− An integer value representing the millisecond segment of the time reading.
The above is the detailed content of How to create a date object and what parameters does it include?. For more information, please follow other related articles on the PHP Chinese website!