chore: update time format
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Form, Label, Modal, Pagination, Table } from 'semantic-ui-react';
|
||||
import { API, openPage, showError, showSuccess, showWarning } from '../helpers';
|
||||
import { API, openPage, showError, showSuccess, showWarning, timestamp2string } from '../helpers';
|
||||
|
||||
import { ITEMS_PER_PAGE } from '../constants';
|
||||
|
||||
@@ -70,13 +70,11 @@ function renderChannel(channel) {
|
||||
}
|
||||
|
||||
function renderTimestamp(timestamp) {
|
||||
const date = new Date(timestamp * 1000);
|
||||
return (
|
||||
<>
|
||||
{date.getFullYear()}-{date.getMonth() + 1}-{date.getDate()}{' '}
|
||||
{date.getHours()}:{date.getMinutes()}:{date.getSeconds()}
|
||||
{timestamp2string(timestamp)}
|
||||
</>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function renderStatus(status) {
|
||||
|
||||
@@ -102,3 +102,41 @@ export function removeTrailingSlash(url) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
export function timestamp2string(timestamp) {
|
||||
let date = new Date(timestamp * 1000);
|
||||
let year = date.getFullYear().toString();
|
||||
let month = (date.getMonth() + 1).toString();
|
||||
let day = date.getDate().toString();
|
||||
let hour = date.getHours().toString();
|
||||
let minute = date.getMinutes().toString();
|
||||
let second = date.getSeconds().toString();
|
||||
if (month.length === 1) {
|
||||
month = '0' + month;
|
||||
}
|
||||
if (day.length === 1) {
|
||||
day = '0' + day;
|
||||
}
|
||||
if (hour.length === 1) {
|
||||
hour = '0' + hour;
|
||||
}
|
||||
if (minute.length === 1) {
|
||||
minute = '0' + minute;
|
||||
}
|
||||
if (second.length === 1) {
|
||||
second = '0' + second;
|
||||
}
|
||||
return (
|
||||
year +
|
||||
'-' +
|
||||
month +
|
||||
'-' +
|
||||
day +
|
||||
' ' +
|
||||
hour +
|
||||
':' +
|
||||
minute +
|
||||
':' +
|
||||
second
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import { Card, Grid, Header, Segment } from 'semantic-ui-react';
|
||||
import { API, showError, showNotice } from '../../helpers';
|
||||
import { API, showError, showNotice, timestamp2string } from '../../helpers';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
|
||||
const Home = () => {
|
||||
@@ -22,8 +22,7 @@ const Home = () => {
|
||||
|
||||
const getStartTimeString = () => {
|
||||
const timestamp = statusState?.status?.start_time;
|
||||
const date = new Date(timestamp * 1000);
|
||||
return date.toLocaleString();
|
||||
return timestamp2string(timestamp);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user