How JavaScript gets the current timestamp

Source: Internet
Author: User

定义日期:

Date 对象用于处理日期和时间。 可以通过 new 关键词来定义 Date 对象。以下代码定义了名为 myDate 的 Date 对象: var myDate= new Date() 注释:Date 对象自动使用当前的日期和时间作为其初始值。 var myDate= new Date(2013-1-10) Javascript 获取当前时间戳(毫秒级别): 第一种方法: var timestamp1 = Date.parse( new Date()); 结果:1372751992000 第二种方法: var timestamp2 = ( new Date()).valueOf(); 结果:1372751992066 第三种方法: var timestamp3 = new Date().getTime(); 结果:1372751992066 alert(timestamp1); alert(timestamp2); alert(timestamp3); 备注:第一种获取的时间戳是把毫秒改成000显示,第二种和第三种是获取了当前毫秒的时间戳。

How JavaScript gets the current timestamp

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.