datetime - Comment obtenir un timetamp en JavaScript

Mots clés : javascriptdatetimetimestampdate-arithmeticjavascript

meilleur 5 Réponses datetime - Comment obtenir un timetamp en JavaScript

vote vote

91

+ new Date() 
if (!Date.now) {     Date.now = function() { return new Date().getTime(); } } 
Math.floor(Date.now() / 1000) 
Date.now() / 1000 | 0 
new Date().getTime() 
Math.round(new Date().getTime()/1000) 
new Date().valueOf() 
var timeStampInMs = window.performance && window.performance.now && window.performance.timing && window.performance.timing.navigationStart ? window.performance.now() + window.performance.timing.navigationStart : Date.now();  console.log(timeStampInMs, Date.now());
vote vote

89

+new Date 
Date.now() 
vote vote

80

var unix = Math.round(+new Date()/1000); 
var milliseconds = new Date().getTime(); 
vote vote

65

var time = Date.now || function() {   return +new Date; };  time(); 
vote vote

57

Date.now() /1000 |0 
Math.floor(Date.now() /1000); 
new Date/1e3|0 
if (!Date.now) {     Date.now = function now() {         return new Date().getTime();     }; } 
Math.floor(Date.now() / 1000) 
const relativeTime = (() => {     const start = Date.now();     return () => Date.now() - start; })(); 

Questions similaires