Home >Web Front-end >JS Tutorial >Three ways to get the current timestamp in JS

Three ways to get the current timestamp in JS

怪我咯
怪我咯Original
2017-03-31 09:39:513637browse

JavaScript Get the current timestamp:

First method:

var timestamp = Date.parse (new Date());

Result: 1280977330000

Second method:

var timestamp = (new Date()).valueOf();

Result: 1280977330748

Third method:

var timestamp=new Date().getTime();

Result: 1280977330748

The first type: the timestamp obtained is to change the millisecond to 000 for display.

The second and third types are to obtain the timestamp of the current millisecond.


The above is the detailed content of Three ways to get the current timestamp in JS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn