Documentation
Webflow
Code
Setup: External Scripts
External Scripts in Webflow
Make sure to always put the External Scripts before the Javascript step of the resource.
In this video you learn where to put these in your Webflow project? Or how to include a paid GSAP Club plugin in your project?
HTML
Step 1: Copy structure to Webflow
Copy structure to Webflow
In the video below we described how you can copy + paste the structure of this resource to your Webflow project.
Copy to Webflow
Webflow structure is not required for this resource.
Step 1: Add HTML
HTML
<p data-current-time>
<span data-current-time-hours>9</span>:
<span data-current-time-minutes>00</span>:
<span data-current-time-seconds>24</span>
<span data-current-time-timezone>CET</span>
</p>
HTML structure is not required for this resource.
Step 2: Add CSS
CSS
Step 2: Add custom Javascript
Custom Javascript in Webflow
In this video, Ilja gives you some guidance about using JavaScript in Webflow:
Step 2: Add Javascript
Step 3: Add Javascript
Javascript
function initDynamicCurrentTime() {
const defaultTimezone = "Europe/Amsterdam";
// Helper function to format numbers with leading zero
const formatNumber = (number) => number.toString().padStart(2, '0');
// Function to create a time formatter with the correct timezone
const createFormatter = (timezone) => {
return new Intl.DateTimeFormat([], {
timeZone: timezone,
timeZoneName: 'short',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false, // Optional: Remove to match your simpler script
});
};
// Function to parse the formatted string into parts
const parseFormattedTime = (formattedDateTime) => {
const match = formattedDateTime.match(/(\d+):(\d+):(\d+)\s*([\w+]+)/);
if (match) {
return {
hours: match[1],
minutes: match[2],
seconds: match[3],
timezone: match[4], // Handles both GMT+X and CET cases
};
}
return null;
};
// Function to update the time for all elements
const updateTime = () => {
document.querySelectorAll('[data-current-time]').forEach((element) => {
const timezone = element.getAttribute('data-current-time') || defaultTimezone;
const formatter = createFormatter(timezone);
const now = new Date();
const formattedDateTime = formatter.format(now);
const timeParts = parseFormattedTime(formattedDateTime);
if (timeParts) {
const {
hours,
minutes,
seconds,
timezone
} = timeParts;
// Update child elements if they exist
const hoursElem = element.querySelector('[data-current-time-hours]');
const minutesElem = element.querySelector('[data-current-time-minutes]');
const secondsElem = element.querySelector('[data-current-time-seconds]');
const timezoneElem = element.querySelector('[data-current-time-timezone]');
if (hoursElem) hoursElem.textContent = hours;
if (minutesElem) minutesElem.textContent = minutes;
if (secondsElem) secondsElem.textContent = seconds;
if (timezoneElem) timezoneElem.textContent = timezone;
}
});
};
// Initial update and interval for subsequent updates
updateTime();
setInterval(updateTime, 1000);
}
// Initialize on DOMContentLoaded
document.addEventListener('DOMContentLoaded', () => {
initDynamicCurrentTime();
});
Step 3: Add custom CSS
Step 2: Add custom CSS
Custom CSS in Webflow
Curious about where to put custom CSS in Webflow? Ilja explains it in the below video:
CSS
Implementation
Default
When no timezone is added to the [data-current-time]
data attribute it will get the timezone defined in the script, as defaut: Europe/Amsterdam
Adding Timezone
You can add a timezone by hand by passing it in the [data-current-time="Europe/Amsterdam"]
attribute
Show less information
It's possible to remove the seconds or timezone dindication. The script will still work fine.
List with timezones
You can find a full list with timezone (TZ Identifier) options on Wikipedia
Examples:
- Africa/Lagos
- America/New_York
- Asia/Tel_Aviv
- Australia/West
Resource Details
Last updated
January 22, 2025
Type
Osmo Basics
Category
Utilities & Scripts
Need help?
Join Slack