reformatted datetime to be consistent
This commit is contained in:
@@ -1,8 +1,18 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% 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>
|
<script>
|
||||||
// JavaScript to update the datetime dynamically
|
// 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() {
|
function updateTime() {
|
||||||
const dateElement = document.getElementById('datetime');
|
const dateElement = document.getElementById('datetime');
|
||||||
const currentTime = new Date(dateElement.dataset.time);
|
const currentTime = new Date(dateElement.dataset.time);
|
||||||
@@ -11,13 +21,13 @@
|
|||||||
currentTime.setSeconds(currentTime.getSeconds() + 1);
|
currentTime.setSeconds(currentTime.getSeconds() + 1);
|
||||||
|
|
||||||
// Format the datetime as a readable string
|
// Format the datetime as a readable string
|
||||||
const formattedTime = currentTime.toLocaleString();
|
const formattedTime = formatDateTime(currentTime);
|
||||||
|
|
||||||
// Update the displayed datetime
|
// Update the displayed datetime
|
||||||
dateElement.textContent = formattedTime;
|
dateElement.textContent = formattedTime;
|
||||||
|
|
||||||
// Update the data-time attribute for the next update
|
// Update the data-time attribute for the next update
|
||||||
dateElement.dataset.time = currentTime.toISOString();
|
dateElement.dataset.time = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the datetime every second
|
// Update the datetime every second
|
||||||
|
|||||||
Reference in New Issue
Block a user