How to create a date object and what parameters does it include?

王林
Release: 2023-09-08 10:13:06
forward
873 people have browsed it

How to create a date object and what parameters does it include?

#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 ])
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template