Skip to content

Commit

Permalink
added showTimestampInLocalTime
Browse files Browse the repository at this point in the history
  • Loading branch information
sctop committed Nov 18, 2023
1 parent 413a8db commit 295d73a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions static/js/time_show.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 295d73a

Please sign in to comment.