Created
September 19, 2020 06:13
-
-
Save anlai/3fd9ce1bfcb7919522508cf846eec782 to your computer and use it in GitHub Desktop.
Simple script to convert an ISO 1806 UTC datetime to a localized date time string on page load.
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 localizeDateTime = (function(){ | |
window.addEventListener('load', function(){ | |
const toLocalize = document.querySelectorAll('.localize-datetime'); | |
toLocalize.forEach(element => { | |
let input = element.innerHTML; | |
let date = new Date(input); | |
element.innerHTML = `${date.toLocaleDateString()} ${date.toLocaleTimeString()}` | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment