Skip to content

Instantly share code, notes, and snippets.

@k-yle
Last active June 8, 2016 04:32
Show Gist options
  • Save k-yle/75990722a43b3f07954f68ec149c1046 to your computer and use it in GitHub Desktop.
Save k-yle/75990722a43b3f07954f68ec149c1046 to your computer and use it in GitHub Desktop.
🕒 get the true time in any timezone
const Time = UTCoffset => {
var d = new Date(),
utc = d.getTime() + (d.getTimezoneOffset() * 60000),
n = new Date(utc + (3600000 * UTCoffset)),
f = n.toLocaleString().toString().split(', '),
e = f[0].split('/');
if (Number(e[0]) < 10)
e[0] = 0 + e[0];
if (Number(e[1]) < 10)
e[1] = 0 + e[1];
return [`${e[1]}-${e[0]}-${e[2]}`, f[1]]; //DST - https://msdn.microsoft.com/en-us/library/jj863688(v=vs.85).aspx
}
if (typeof module != 'undefined')
module.exports = Time;
@k-yle
Copy link
Author

k-yle commented Jun 1, 2016

Usage:

var time = require('time');
time(+12); //Time in UTC + 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment