Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the Date object?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report