From 295d73a4242721869c8407960373c6b88cd543bf Mon Sep 17 00:00:00 2001 From: sctop <2094880085@qq.com> Date: Sat, 18 Nov 2023 20:43:02 +0800 Subject: [PATCH] added showTimestampInLocalTime --- static/js/time_show.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/static/js/time_show.js b/static/js/time_show.js index cecf817..03ff16d 100644 --- a/static/js/time_show.js +++ b/static/js/time_show.js @@ -36,4 +36,17 @@ function showProjectTime() { setHtmlElementById("project-time-hour", result.hours); setHtmlElementById("project-time-minute", result.minutes); setHtmlElementById("project-time-second", result.seconds); +} + +function showTimestampInLocalTime(timestamp) { + // by Google Bard + const utcTimestamp = timestamp; + + const localDate = new Date(utcTimestamp * 1000); + const formattedLocalDate = localDate.getFullYear() + '-' + (localDate.getMonth() + 1).toString().padStart(2, '0') + '-' + localDate.getDate().toString().padStart(2, '0'); + const formattedLocalTime = localDate.getHours().toString().padStart(2, '0') + ':' + localDate.getMinutes().toString().padStart(2, '0') + ':' + localDate.getSeconds().toString().padStart(2, '0'); + + const formattedLocalDatetime = formattedLocalDate + ' ' + formattedLocalTime; + + return formattedLocalDatetime; } \ No newline at end of file