Last active
February 17, 2020 01:02
-
-
Save bemosior/1ec84cb2fe07205addd192fdb7d7c12d to your computer and use it in GitHub Desktop.
WordPress Divi Button Date Localization
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.27/moment-timezone-with-data-2012-2022.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.7/jstz.min.js"></script> | |
<script> | |
localizeTime("et_pb_button_one","2020-02-20 17:00",true); | |
localizeTime("et_pb_button_two","2020-02-05 22:00",false); | |
function localizeTime(buttonClass, timeString, full) { | |
if (!sessionStorage.getItem('timezone')) { | |
var tz = jstz.determine() || 'UTC'; | |
sessionStorage.setItem('timezone', tz.name()); | |
} | |
var currTz = sessionStorage.getItem('timezone'); | |
var momentTime = moment.utc(timeString); | |
var tzTime = momentTime.tz(currTz); | |
// var formattedTime = tzTime.format('MMM Do, h:mmA zz'); | |
var formattedTime = tzTime.format('h:mmA zz'); | |
if (full === true) { | |
formattedTime = '<del>' + formattedTime + '</del> FULL!'; | |
} | |
var button = document.getElementsByClassName(buttonClass); | |
var i; | |
for (i = 0; i < button.length; i++) { | |
button[i].innerHTML = formattedTime; | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment