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: Select all
[epoch]{TEXT}[/epoch]
Code: Select all
<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>
Code: Select all
replace {TEXT} with a unix timestamp such as one generated from https://www.epochconverter.com/
Time is displayed MM/DD/YYY HH:MM