Skip to content

Instantly share code, notes, and snippets.

@erickvasilev
Last active December 22, 2020 12:52
Show Gist options
  • Save erickvasilev/aa87f17e0514630343ce60a10e096cff to your computer and use it in GitHub Desktop.
Save erickvasilev/aa87f17e0514630343ce60a10e096cff to your computer and use it in GitHub Desktop.
Date & Time Converter Native - Erick Vasilev
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + (h*60*60*1000));
return this;
}
const singapore_time = new Date().addHours(8); // GMT +8
const date_time = singapore_time.getTime();
const current_timestamp = singapore_time.getTime().toString();
const date_to_utc = ( new Date(date_time)).toUTCString();
const utc_to_epoch = Date.parse(date_to_utc);
console.log(date_to_utc) // Tue, 22 Dec 2020 09:38:28 GMT
console.log(utc_to_epoch) // 1608629908000
console.log(current_timestamp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment