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 use of Date objects in JavaScript

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

Share

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

This article mainly shows you "what is the use of Date objects in JavaScript", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is the use of Date objects in JavaScript" this article.

Date object constructor

The Date object has several constructors.

NewDate () newDate (milliseconds) newDate (datestring) newDate (year,month) newDate (year,month,day) newDate (year,month,day,hours) newDate (year,month,day,hours,minutes) newDate (year,month,day,hours,minutes,seconds) newDate (year,month,day,hours,minutes,seconds,microseconds) Date object constructor parameter description

Milliseconds-the number of milliseconds from the start time defined internally by JavaScript on January 1st, 1970

Datestring-the date and time represented by the string. This string can be converted using Date.parse ()

Year-four-digit year, if the value is 0-99, add 1900 to it

The month between month-0 (for January) and November (for December)

Date between day-1-31

Hours between hours-0 (for midnight)-23

Minutes between minutes-0-59

Number of seconds between seconds-0-59

Number of milliseconds between microseconds-0-999

Return value of Date object

If there are no parameters, the current date is returned

If the parameter is a number, the number is treated as a millisecond value and converted to a date

If the parameter is a string, the string is treated as a string representation of the date and converted to a date

You can also use six constructors to precisely define and return time

Example

Vard1=newDate (); [xss_clean] (d1.toString ()); vard2=newDate ("2009-08-08 12:12:12); [xss_clean] (d2.toString ()); vard3=newDate (2009 Leigh 8); [xss_clean] (d3.toString ()); Date, as a built-in object of JavaScript, must be created using new.

The internal representation of the Date object in JavaScript is the number of milliseconds (timestamp) since midnight (GMT time) on January 1, 1970, and here we also refer to the internal representation of Date as timestamp. You can use getTime () to convert the Date object to the timestamp of Date, and the method setTime () converts the timestamp of Date to the standard form of Date.

The Date function uses syntax

Date. Method name (parameter 1, parameter 2, Date.). The method name (); date represents an instance of a date object, and Date represents a date object, date. The member function called by the method name is the object

Date. The static function called by the method name is the object

Example

Vard=newDate (); vard2=Date.UTC (); JavaScript_Date functions are classified by function

Date acquisition class function

Date () function-- the constructor of Date object

GetDate () function-returns the number of days in the month in the date object (1-31)

GetDay () function-returns the number of days of the week in the date object (0-6)

GetFullYear () function-returns a four-digit year in a date object

GetHours () function-returns the number of hours in the date object (0-23)

GetMilliseconds () function-returns the number of milliseconds in the date object (0-999)

GetMinutes () function-returns the number of minutes in the date object (0-59)

GetMonth () function-returns the number of months in the date object (0-11)

GetSeconds () function-returns the number of seconds in the date object (0-59)

GetTime () function-returns the timestamp representation of the date object (in milliseconds)

GetTimezoneOffset () function-returns the time difference between the local time and the current date represented by UTC, in minutes

GetUTCDate () function-returns the day of the month (1-31) in the date object in Universal Standard time (UTC)

GetUTCDay () function-returns the day of the week (0-6) in the date object in Universal Standard time (UTC)

GetUTCFullYear () function-returns the four-digit year in the date object in Universal Standard time (UTC)

GetUTCHours () function-returns the number of hours in the date object expressed in Universal Standard time (UTC) (0-23)

GetUTCMilliseconds () function-returns the number of milliseconds in the date object expressed in Universal Standard time (UTC) (0-999)

GetUTCMinutes () function-returns the number of minutes in the date object expressed in Universal Standard time (UTC) (0-59)

GetUTCMonth () function-returns the number of months in the date object expressed in Universal Standard time (UTC) (0-11)

GetUTCSeconds () function-returns the number of seconds in the date object expressed in Universal Standard time (UTC) (0-59)

GetYear () function-returns the year of the date object (real year minus 1900)

Date.UTC () function-returns the number of milliseconds (timestamp) between the date object and midnight Universal Standard time (UTC) on January 1, 1970.

Date setting class function

SetDate () function-sets the day of the month in the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetFullYear () function-sets the year, month, and day in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetHours () function-sets the hours, minutes, seconds, and milliseconds of the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetMilliseconds () function-sets the number of milliseconds for the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetMinutes () function-sets the minutes, seconds, milliseconds of the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetMonth () function-sets the month and day in the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetSeconds () function-sets the day of the month in the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetTime () function-sets the date object in milliseconds and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCDate () function-sets the day of the month in the date object in Universal Standard time (UTC) and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCFullYear () function-sets the year, month, and day in the date object in Universal Standard time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCHours () function-sets the hours, minutes, seconds, and milliseconds in the date object in Universal Standard time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCMilliseconds () function-sets the number of milliseconds in the date object in Universal Standard time (UTC) and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCMinutes () function-sets the minutes and seconds in the date object in Universal Standard time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCMonth () function-sets the month and day in UTC in the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCSeconds () function-sets the seconds, milliseconds in the date object in Universal Standard time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetYear () function-sets the year of the date object (real year minus 1900)

Date printing class function

ToDateString () function-returns a string representation of the date portion of the date object

ToGMTString () function-returns a string representation of Greenwich mean time (GMT) of the date object

ToLocaleDateString function-returns a localized string for the date portion of the date object

ToLocaleTimeString function-returns a localized string for the time portion of the date object

ToTimeString () function-A string that returns the time portion of the date object

ToUTCString function-returns a string representation of the world standard time (UTC) of the date object

Date parsing class function

Date.parse () function-parses the string of a date and returns the number of milliseconds (timestamp) between that date and midnight on January 1, 1970.

JavaScript_Date functions are classified by alphabet

Date () function-- the constructor of Date object

GetDate () function-returns the number of days in the month in the date object (1-31)

GetDay () function-returns the number of days of the week in the date object (0-6)

GetFullYear () function-returns a four-digit year in a date object

GetHours () function-returns the number of hours in the date object (0-23)

GetMilliseconds () function-returns the number of milliseconds in the date object (0-999)

GetMinutes () function-returns the number of minutes in the date object (0-59)

GetMonth () function-returns the number of months in the date object (0-11)

GetSeconds () function-returns the number of seconds in the date object (0-59)

GetTime () function-returns the timestamp representation of the date object (in milliseconds)

GetTimezoneOffset () function-returns the time difference between the local time and the current date represented by UTC, in minutes

GetUTCDate () function-returns the day of the month (1-31) in the date object in Universal Standard time (UTC)

GetUTCDay () function-returns the day of the week (0-6) in the date object in Universal Standard time (UTC)

GetUTCFullYear () function-returns the four-digit year in the date object in Universal Standard time (UTC)

GetUTCHours () function-returns the number of hours in the date object expressed in Universal Standard time (UTC) (0-23)

GetUTCMilliseconds () function-returns the number of milliseconds in the date object expressed in Universal Standard time (UTC) (0-999)

GetUTCMinutes () function-returns the number of minutes in the date object expressed in Universal Standard time (UTC) (0-59)

GetUTCMonth () function-returns the number of months in the date object expressed in Universal Standard time (UTC) (0-11)

GetUTCSeconds () function-returns the number of seconds in the date object expressed in Universal Standard time (UTC) (0-59)

GetYear () function-returns the year of the date object (real year minus 1900)

Date.parse () function-parses the string of a date and returns the number of milliseconds (timestamp) between that date and midnight on January 1, 1970.

SetDate () function-sets the day of the month in the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetFullYear () function-sets the year, month, and day in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetHours () function-sets the hours, minutes, seconds, and milliseconds of the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetMilliseconds () function-sets the number of milliseconds for the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetMinutes () function-sets the minutes, seconds, milliseconds of the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetMonth () function-sets the month and day in the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetSeconds () function-sets the day of the month in the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetTime () function-sets the date object in milliseconds and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCDate () function-sets the day of the month in the date object in Universal Standard time (UTC) and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCFullYear () function-sets the year, month, and day in the date object in Universal Standard time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCHours () function-sets the hours, minutes, seconds, and milliseconds in the date object in Universal Standard time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCMilliseconds () function-sets the number of milliseconds in the date object in Universal Standard time (UTC) and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCMinutes () function-sets the minutes and seconds in the date object in Universal Standard time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCMonth () function-sets the month and day in UTC in the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetUTCSeconds () function-sets the seconds, milliseconds in the date object in Universal Standard time (UTC), and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, 1970

SetYear () function-sets the year of the date object (real year minus 1900)

ToDateString () function-returns a string representation of the date portion of the date object

ToGMTString () function-returns a string representation of Greenwich mean time (GMT) of the date object

ToLocaleDateString function-returns a localized string for the date portion of the date object

ToLocaleTimeString function-returns a localized string for the time portion of the date object

ToTimeString () function-A string that returns the time portion of the date object

ToUTCString function-returns a string representation of the world standard time (UTC) of the date object

Date.UTC () function-returns the number of milliseconds (timestamp) between the date object and midnight Universal Standard time (UTC) on January 1, 1970.

The above is all the content of the article "what is the use of Date objects in JavaScript?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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