Some questions about JavaScript time

Source: Internet
Author: User

1. Ask for the current time.

var curdate = new Date ();

2. Ask for the day before the current time

var predate = new Date (Curdate.gettime () -24*60*60*1000);

3. Time format conversion.

You can find the date format above. Mon June 17:21:50 gmt+0800 (China Standard Time)

We are free to convert the format, using the date of the function above as the parameter.

function FormatDateTime (date) {      // Converts the time to the desired format    var y = date.getfullyear ();     = Date.getmonth () + 1;     = M < 10? ' 0 ' + m:m;     = date.getdate ();     = d < 10? (' 0 ' + D): D;     = date.gethours ();     = h < 10? (' 0 ' + D): h;     = date.getminutes ();     = Mi < 10? (' 0 ' + mi): mi;    Console.log (h);    Console.log (d);     return y + ' year ' + M + ' month ' + d+ ' Day ' + H + ': ' + mi;}

4. Timestamp 10-bit and 13-bit differences

The accuracy is different, 10 bits to 13 bits multiplied by 1000, 13 bits into 10 bits divided by 1000.java is 13 bits, PHP is 10 bits.

Some questions about JavaScript time

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.