reformatted datetime to be consistent

This commit is contained in:
Nico Melone
2025-01-22 12:51:02 -06:00
parent efe56a5f29
commit 7a5048e127

View File

@@ -1,8 +1,18 @@
{% extends "base.html" %}
{% block content %}
<h1 id="datetime" data-time="{{now.isoformat()}}">{{now.isoformat()}}</h1>
<h1 id="datetime" data-time="{{now.isoformat()}}">{{now.strftime("%Y/%m/%d %H:%M:%S")}}</h1>
<script>
// JavaScript to update the datetime dynamically
function formatDateTime(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
}
function updateTime() {
const dateElement = document.getElementById('datetime');
const currentTime = new Date(dateElement.dataset.time);
@@ -11,13 +21,13 @@
currentTime.setSeconds(currentTime.getSeconds() + 1);
// Format the datetime as a readable string
const formattedTime = currentTime.toLocaleString();
const formattedTime = formatDateTime(currentTime);
// Update the displayed datetime
dateElement.textContent = formattedTime;
// Update the data-time attribute for the next update
dateElement.dataset.time = currentTime.toISOString();
dateElement.dataset.time = currentTime;
}
// Update the datetime every second