Last active
September 8, 2020 11:09
-
-
Save jerry42/186f11c29353c7666dd72ef915ba017a to your computer and use it in GitHub Desktop.
ES6 script to update MySQL DATETIME to local ( Lang & Timezone ) date in HTML on document ready
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
# HTML example <span class="dateTZ">2020-09-08 13:07:42</span> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment-with-locales.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone-with-data.min.js"></script> | |
<script> | |
function updateDateLocalTZ(classID) | |
{ | |
$(`.${classID}`).html(moment.tz(moment.utc($(`.${classID}`).html()), moment.tz.guess(true)).format('llll')) | |
} | |
$( document ).ready(function() { | |
var userLang = navigator.language || navigator.userLanguage; | |
moment.locale(userLang.substring(0,2)) | |
updateDateLocalTZ('dateTZ') | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment