JSFiddle - React, Tailwind, and code Playground

by Victor Almeida

HTML

<span class="epoch"></span>

JavaScript

window.onload = function() {
    // Get the current timestamp in seconds
    let currentTimestamp = Math.floor(Date.now() / 1000);

    // Create a Date object from the current timestamp
    let date = new Date(currentTimestamp * 1000);

    // Format the date
    let formattedDate = date.toLocaleDateString(undefined, {
        weekday: 'long',
        year: 'numeric',
        month: 'short',
        day: 'numeric',
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit',
        timeZoneName: 'short'
    });

    // Find the span element and set its content
    let epochSpan = document.querySelector('.epoch');
    if (epochSpan) {
        epochSpan.innerText = formattedDate;
    }
};