Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom Date Time in Webflow
var Webflow = Webflow || [];
Webflow.push(function() {
let timeFormatPT = new Date('{{wf {"path":"added-date","transformers":[{"name":"date","arguments":["YYYY-MM-DD hh:mm a"]\}],"type":"Date"\} }} PDT'.replace(/-/g, "/"))
// Automate Day Light Savings
const DLS = timeFormatPT.getTimezoneOffset()/60 === 7 ? 'PST' : 'PDT';
timeFormatPT = new Date(`{{wf {"path":"added-date","transformers":[{"name":"date","arguments":["YYYY-MM-DD hh:mm a"]\}],"type":"Date"\} }} ${DLS}`.replace(/-/g, "/"))
const date = {
weekday: "long",
month: "short",
day: "numeric",
year: "numeric",
};
const time = {
hour: '2-digit',
minute: "numeric",
hour12: true,
timeZoneName: "short",
};
$('.pdate').html(Intl.DateTimeFormat(navigator.language, date).format(timeFormatPT))
$('.ptime').html(Intl.DateTimeFormat(navigator.language, time).format(timeFormatPT))
})
var Webflow = Webflow || [];
Webflow.push(function() {
const timeFormatWF = new Date('{{wf {"path":"added-date","transformers":[{"name":"date","arguments":["MMM DD, YYYY"]\}],"type":"Date"\} }}'.replace(/-/g, "/"));
let timeFormatPT = new Date('{{wf {"path":"added-date","transformers":[{"name":"date","arguments":["YYYY-MM-DD hh:mm a"]\}],"type":"Date"\} }} PDT'.replace(/-/g, "/"))
const date = {
weekday: "long",
month: "short",
day: "numeric",
year: "numeric",
};
const time = {
hour: '2-digit',
minute: "numeric",
hour12: true,
timeZoneName: "short",
};
$('.wfdate').html(Intl.DateTimeFormat(navigator.language, date).format(timeFormatWF))
$('.pdate').html(Intl.DateTimeFormat(navigator.language, date).format(timeFormatPT))
$('.wftime').html(Intl.DateTimeFormat(navigator.language, time).format(timeFormatWF))
$('.ptime').html(Intl.DateTimeFormat(navigator.language, time).format(timeFormatPT))
})
@zeshhaan
Copy link
Author

zeshhaan commented Aug 11, 2021

To change language, try replacing navigator.language with 'en-US'.
For other language formats, check this link for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment