diff --git a/src/containers/global/Timestamp.tsx b/src/containers/global/Timestamp.tsx index f410c58d..ac5581dd 100644 --- a/src/containers/global/Timestamp.tsx +++ b/src/containers/global/Timestamp.tsx @@ -1,16 +1,14 @@ import { Tooltip } from 'antd' -import moment from 'moment' import { Component } from 'react' +import Utils from '../../utils/Utils' export default class Timestamp extends Component<{ timestamp: string }, {}> { render() { const timestamp = this.props.timestamp + return ( - - - {/* 'L' represents localized date format, 'LT' represents localized time format */} - {moment(new Date(timestamp)).format('L, LT')} - + + {Utils.getLocalizedDateTime(timestamp)} ) } diff --git a/src/utils/Utils.tsx b/src/utils/Utils.tsx index 2c3195f1..098f1c3f 100644 --- a/src/utils/Utils.tsx +++ b/src/utils/Utils.tsx @@ -1,3 +1,4 @@ +import moment from 'moment' import React, { ReactElement } from 'react' // eslint-disable-next-line import/no-anonymous-default-export @@ -171,4 +172,19 @@ export default { return newObject }, + + getLocalizedDateTime(timestamp: string) { + const formattedDate = new Date(timestamp).toLocaleString('default', { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: '2-digit', + minute: '2-digit', + }) + return formattedDate + }, + + getRelativeDateTime(timestamp: string) { + return moment(new Date(timestamp)).fromNow() + }, }