JavaScript gets timestamp, date formatting

Source: Internet
Author: User
One, JS get timestamp: The first method: var timestamp1 = date.parse (New Date ()); The second method: var timestamp2 = (new Date ()). ValueOf (); The third method: var Timestamp3 = new Date (). GetTime (); alert (TIMESTAMP1);//Results: 1372751992000alert (TIMESTAMP2);//Results: 1372751992066alert (Timestamp3);/results: 1372751992066   Note: The first obtained timestamp is to change the millisecond to 000, the second and third is to get the timestamp of the current millisecond.  Second, timestamp format: function FormatDate (now) {var year = Now.getfullyear (), month = Now.getmonth () + 1, date = Now.getdate (),   hour = Now.gethours (), minute = Now.getminutes (), second = Now.getseconds (); Return year + "-" + month + "-" + Date + "" + Hour + ":" + Minute + ":" + Second;} var d = new Date (); Alert (FormatDate (d));//2016-12-12 12-12-12

JavaScript gets timestamp, date formatting

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.