JavaScript Fetch API Example
You don't always need a massive framework like React or Angular. Modern browsers support the `fetch()` API natively, allowing you to get atomic time data with just a few lines of plain JavaScript.
JAVASCRIPT
// 1. Select the DOM element
const display = document.getElementById('time-display');
// 2. Fetch data
fetch('https://time.now/developer/api/timezone/Europe/London')
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.json();
})
.then(data => {
// 3. Update the UI
console.log(data);
display.innerText = `London Time: ${data.datetime}`;
})
.catch(error => console.error('Error:', error));
Why use Time.Now for Frontend?
- Zero dependencies
- Works in all modern browsers
- Copy-paste ready