Js_ the conversion between the timestamp and the time format.

Source: Internet
Author: User

As for my understanding, it is simple and clear:

Timestamp: A date is represented by a number, which is the number of seconds of this date.

Date: It is our common form of time expression.

Time stamping for the general look at the time is not straightforward, but in the program of the world can be a big role.

Gets the current timestamp:

1 // Gets the current timestamp (in s) 2 var timestamp = date.parse (new  Date ()); 3 timestamp = timestamp/1000;

To get a timestamp for a date:

1 // gets the timestamp of a time format 2 var stringtime = "2017-11-05 10:21:12"; 3 var timestamp2 = Date.parse (new  Date (stringtime)); 4 timestamp2 = timestamp2/1000;

Convert a timestamp to a date:

1 //change the current time to a time format string2 varTimestamp3 = 1403058804;3 varNewdate =NewDate ();4Newdate.settime (Timestamp3 * 1000);5 //Wed June6 Console.log (newdate.todatestring ());7 //Wed, June 02:33:24 GMT8 Console.log (newdate.togmtstring ());9 //2014-06-18t02:33:24.000zTen Console.log (newdate.toisostring ()); One //2014-06-18t02:33:24.000z A Console.log (Newdate.tojson ()); - //June 18, 2014 - Console.log (newdate.tolocaledatestring ()); the //June 18, 2014 morning 10:33:24 - Console.log (newdate.tolocalestring ()); - //Morning 10:33:24 - Console.log (newdate.tolocaletimestring ()); + //Wed June 10:33:24 gmt+0800 (China Standard Time) - Console.log (newdate.tostring ()); + //10:33:24 gmt+0800 (China Standard Time) A Console.log (newdate.totimestring ()); at //Wed, June 02:33:24 GMT -Console.log (Newdate.toutcstring ());

Js_ the conversion between the timestamp and the time format.

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.