Get a GMT timestamp using JavaScript

 

Dates created this way use the local time zone, so the date created is incorrect. To set the time zone of a particular date object, you must construct it from a date string that contains the time zone. (I had trouble getting this to work in an older Android browser.)

Note that getTime() returns milliseconds, not ordinary seconds.

 

For a UTC/Unix timestamp, the following should suffice:

Math.floor((new Date()).getTime() / 1000)

 

 

const gmt_Times_tamp = new Date().getTime();
console.log(gmt_Times_tamp );

const gmt_Times_tamp1 = new Date().toUTCString();
console.log(gmt_Times_tamp1 );

Tags:

Share:

Related posts