Created
September 17, 2020 09:05
-
-
Save cevek/1eea25f0aba69540be54745d620d3cea 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
const offset = new Date().getTimezoneOffset(); | |
function getDigit(s, p) { | |
return s.charCodeAt(p) - 48; | |
} | |
function parseISOString(d) { | |
return new Date( | |
getDigit(d, 0) * 1000 + getDigit(d, 1) * 100 + getDigit(d, 2) * 10 + getDigit(d, 3), | |
getDigit(d, 5) * 10 + getDigit(d, 6) - 1, | |
getDigit(d, 8) * 10 + getDigit(d, 9), | |
getDigit(d, 11) * 10 + getDigit(d, 12), | |
getDigit(d, 14) * 10 + getDigit(d, 15) - offset, | |
getDigit(d, 17) * 10 + getDigit(d, 18), | |
getDigit(d, 20) * 100 + getDigit(d, 21) * 10 + getDigit(d, 22), | |
); | |
} | |
function toDateString(date) { | |
return pad2(date.getDate()) + '.' + pad2(date.getMonth() + 1) + '.' + date.getFullYear(); | |
} | |
function pad2(n) { | |
return n > 10 ? n : '0' + n; | |
} | |
parseISOString("2020-09-17T09:05:17.212Z") | |
toDateString(new Date()) // "17.09.2020" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment