initial commit (from keybase)
This commit is contained in:
parent
bb23ae70d1
commit
be8d138cd0
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* take a date of assumed timezone and convert to utc
|
||||
*
|
||||
* @param {*} d
|
||||
* @param {*} tz
|
||||
* @returns
|
||||
*/
|
||||
function tzUTC(d, tz) {
|
||||
// first calculate tz difference
|
||||
var date = new Date();
|
||||
var options = {
|
||||
year: 'numeric',
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
second: 'numeric',
|
||||
hour12: false,
|
||||
timeZone: tz
|
||||
};
|
||||
var tzDate = new Intl.DateTimeFormat('en-US', options).format(date)
|
||||
var diff = date - new Date(tzDate);
|
||||
var minutes = Math.floor((diff / 1000) / 60);
|
||||
var localTime = new Date(d);
|
||||
localTime.setMinutes(d.getMinutes() + minutes);
|
||||
return localTime.toUTCString();
|
||||
}
|
Loading…
Reference in New Issue