Js date-related function summary _ javascript tips-js tutorial

Source: Internet
Author: User
Recently I wrote a countdown program, because it often needs to be accessed on the mobile phone end, so jquery is not referenced. I am not used to jquery. The following describes the js date-related functions and the principle of countdown. The Code is as follows:


Var dateTo = new Date ("8:00 1/4/2014 ");


Gets the time object of the specified date. If it is null, the default value is the current time.

The Code is as follows:


Var date = dateTo. getTime ()


Returns the number of milliseconds. the start and end time is the time of January 1, 1970.

The Code is as follows:


Var y = date. getFullYear ();


Get year

The Code is as follows:


Var mm = date. getMonth () + 1;


Get month

The Code is as follows:


Var d = date. getDate ();


Get date

The Code is as follows:


Var h = date. getHours ();


Hours

The Code is as follows:


Var m = date. getMinutes ();


Get minutes

The Code is as follows:


Var s = date. getSeconds ();


Get seconds


The idea of Countdown is to calculate the time difference between the two times, and then use

SetInterval (); execute the corresponding function once per second.

The following functions may be used in this process:

ParseInt ($ trNum );

This function converts a number of the string type into a number.

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.