Created
October 28, 2021 09:38
-
-
Save dsaiztc/f109315cac5b1712b5615e7a27929f8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Date().getTime(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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