Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 1710

Custom BBCode Development and Requests • Show time/date in viewer's own timezone, Unix epoch conversion

$
0
0
This is my first post, sorry if it's wrong. I could not find a bbcode like this anywhere.

I'm not sure what to call this, but this bbcode converts a Unix epoch timestamp to human readable format. You can swap around the format if you like, I'm just American.

BBCode:

Code:

[epoch]{TEXT}[/epoch]
HTML replacement:

Code:

<epoch>{TEXT}</epoch><script>document.addEventListener("DOMContentLoaded", function() {    // Function to convert epoch to human-readable format    function convertEpochToHumanReadable(epoch) {        let date = new Date(epoch * 1000);        let year = date.getFullYear();        let month = ('0' + (date.getMonth() + 1)).slice(-2);        let day = ('0' + date.getDate()).slice(-2);        let hours = ('0' + date.getHours()).slice(-2);        let minutes = ('0' + date.getMinutes()).slice(-2);        let seconds = ('0' + date.getSeconds()).slice(-2);        return `${month}-${day}-${year} ${hours}:${minutes}`;    }    // Find all elements with the custom BBCode    document.querySelectorAll('epoch').forEach(function(element) {        let epochTimestamp = parseInt(element.innerText);        if (!isNaN(epochTimestamp)) {            element.innerText = convertEpochToHumanReadable(epochTimestamp);        }    });});</script>
Help line:

Code:

replace {TEXT} with a unix timestamp such as one generated from https://www.epochconverter.com/Time is displayed MM/DD/YYY HH:MM

Statistics: Posted by defvenom — Thu Jul 11, 2024 1:52 am



Viewing all articles
Browse latest Browse all 1710

Trending Articles