Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
Created October 28, 2021 09:38
Show Gist options
  • Save dsaiztc/f109315cac5b1712b5615e7a27929f8c to your computer and use it in GitHub Desktop.
Save dsaiztc/f109315cac5b1712b5615e7a27929f8c to your computer and use it in GitHub Desktop.
new Date().getTime();
function awsIsoDateTime(awsDate) {
var awsYear = awsDate.getYear() + 1900;
var awsMonth = (awsDate.getMonth() < 9) ? ('0' + (awsDate.getMonth() + 1)) : (awsDate.getMonth() + 1);
var awsDay = (awsDate.getDate() < 9) ? ('0' + awsDate.getDate()) : awsDate.getDate();
var awsHours = (awsDate.getHours() < 10) ? '0' + awsDate.getHours() : awsDate.getHours();
var awsMinutes = (awsDate.getMinutes() < 10) ? '0' + awsDate.getMinutes() : awsDate.getMinutes();
var awsSeconds = (awsDate.getSeconds() < 10) ? '0' + awsDate.getSeconds() : awsDate.getSeconds();
var awsOffsetFlag = (awsDate.getTimezoneOffset() == 0) ? 'Z' : ((awsDate.getTimezoneOffset() > 0) ? '-' : '+');
var awsAbsoluteOffset = Math.abs(awsDate.getTimezoneOffset());
var awsHoursOffset = awsOffsetFlag == 'Z' ? '' : ((awsAbsoluteOffset / 60) < 10) ? ('0' + parseInt(awsAbsoluteOffset / 60)) : (parseInt(awsAbsoluteOffset / 60));
var awsMinutesOffset = awsOffsetFlag == 'Z' ? '' : ((awsAbsoluteOffset % 60) < 10) ? ('0' + parseInt(awsAbsoluteOffset % 60)) : (parseInt(awsAbsoluteOffset % 60));
var awsString = awsYear + '-' + awsMonth + '-' + awsDay + 'T';
awsString += awsHours + ':' + awsMinutes + ':' + awsSeconds + awsOffsetFlag + awsHoursOffset + awsMinutesOffset;
return awsString;
}
awsIsoDateTime(new Date());
function ISODateString(d) {
function pad(n) {return n<10 ? '0'+n : n}
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds())+'Z'
}
ISODateString(new Date());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment