Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the Date object?

Shulou Source: shulou.com Published: 2022-06-02 02:59:52 11月04日 Update

This article introduces you what the Date object is, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Type uses the number of milliseconds that have elapsed since midnight (00:00) on January 1, 1970, UTC (Coordinated Universal Time, International coordinated time) to save the date. The date saved by the Date type can be accurate to 285,616 years before or after January 1, 1970.

How do I use the Date object?

First, you need to get the Date object.

Get Wechat

Var d=new Date ()

When the date object is generated, the current time is returned by default without passing any parameters

Var d=new Date ('2015Uniqqq2')

In the case of passing in parameters, what is obtained is the passed time

Note: this parameter is a string.

Some methods:

1.d.getFullYear () gets the current year. | d.setFullYear (2012) returns the number of milliseconds from January 1, 1970 to the set time |

2.d.getMonth () gets the current month (Note: a small BUG, the current month starts at 0) | | d.setMonth (9) returns the number of milliseconds of the set month from January 1, 1970 to the current year.

3.d.getDate () gets the current date | | d.setDate () same as above

4. When getHours () is obtained

GetMinutes () get minutes

GetSeconds () get seconds

The time acquired by each machine varies because the method returns the local time; it is not international standard time

5. Modification of date

Date.parse ("2015-08-24"); get the number of milliseconds from 1970 to the set time

D.getTime (); gets the milliseconds from 1970 to the current time

D.setTime ()

New Date (time)

Create a date object and specify the number of milliseconds at a specified time

Or modify the time property, var d = new Date (); d.setTime (56521211021)

Case study:

1. Format the date

two。 Get the number of days in a month:

3 、. Calculate the date difference

About what the Date object is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Time date object parameter month content international year year method day more type help different good accurate interest international standard number of days Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Microsoft Redmi Docker Xiaomi