Last active
March 10, 2023 23:09
-
-
Save konami99/5938f874c5439870664c96d5da444c0a to your computer and use it in GitHub Desktop.
Webflow timezone conversion
This file contains hidden or 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://cdn.jsdelivr.net/npm/[email protected]/build/global/luxon.min.js"></script> | |
<script> | |
const defaultTimezone = 'Asia/Taipei'; // Change this to your site time zone https://university.webflow.com/lesson/time-zone | |
const local = luxon.DateTime.local(); | |
const localZoneName = local.zoneName; | |
$(function() { | |
$('.timezone-convert').each(function(index) { | |
const date = $(this).text(); | |
const defaultDateTime = date.replace(' ', 'T') + ' ' + defaultTimezone; | |
const defaultDateTimeObject = luxon.DateTime.fromFormat(defaultDateTime, "yyyy-MM-dd'T'H:mm z", { setZone: true }) | |
const localdateTimeObject = defaultDateTimeObject.setZone(localZoneName); | |
const localString = localdateTimeObject.toLocaleString(luxon.DateTime.DATETIME_FULL); | |
if (!localdateTimeObject.invalid) { | |
$(this).text(date + " (" + localString + ")"); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment