Skip to content

Instantly share code, notes, and snippets.

@anlai
Created September 19, 2020 06:13
Show Gist options
  • Save anlai/3fd9ce1bfcb7919522508cf846eec782 to your computer and use it in GitHub Desktop.
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.
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