Introduction to JavaScript Time function Basics _javascript Skills

Source: Internet
Author: User
Tags current time time and date

JavaScript time functions

JavaScript provides a Date object for calculations of time and date.

The Date object has several constructors:

New Date ()//Current time
Number of milliseconds for new Date (milliseconds)//distance start January 1, 1970
The date and time represented by the new date (datestring)//String. This string can be converted using date.parse () such as "Jannuary 1, 1998 20:13:15"
New Date (year, month, day, hours, minutes, seconds, microseconds)//time value, which can be written without all, not written, defaults to 0


When used, create a Date object, such as:
Dateobj=new Date ();


Then call the function, such as
Year=dateobj.getfullyear ()//Get year value


The following is a list of functions.

To get the class function:
GetDate () function--Return days (1-31)
Getday () function--Returns the number of weeks (0-6)
getFullYear () function--returns four-digit years
GetHours () function--Returns the number of hours (0-23)
Getmilliseconds () function--Returns the number of milliseconds (0-999)
Getminutes () function--Returns the number of minutes (0-59)
GetMonth () function--Returns the number of months (0-11)
Getseconds () function--Number of seconds returned (0-59)
GetTime () function--Returns the timestamp notation (in milliseconds)
GetYear () function--return year (real year minus 1900)

To set a class function:
(The following functions return the number of milliseconds between the date objects from midnight January 1, 1970)
Setdate () function--set the day of the month
setFullYear () function--set year, month, and day
Sethours () function--set hours, minutes, seconds, and milliseconds
Setmilliseconds () function--set the number of milliseconds
Setminutes () function--set minutes, seconds, milliseconds
Setmonth () function--Set month, day
Setseconds () function--set the day of the month
SetTime () function--use milliseconds to set the Date object
Setyear () function--set year (real year minus 1900)


Convert Display class function:
Tolocalstring () function--Returns a localized string representation
tolocaledatestring Function--Returns the localized string for the date part
tolocaletimestring function--a localized string that returns the time part

Relative to the local output, there are:

ToString ()
toDateString ()
toTimeString ()

The difference is that the former is based on different machines that have different local language formats, and the latter is the internal representation format

Date resolution class function

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

Time zone related parts see JavaScript time zone functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.