Fakultas Ilmu Komputer UI

Commit cd739986 authored by FadhilP's avatar FadhilP
Browse files

fix timestamp time

parent 6c010370
const monthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];
function tConvert(time) {
try {
// Check correct time format and split into components
time = time
.toString()
.match(/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
if (time.length > 1) {
// If time format correct
time = time.slice(1, 4); // Remove full string match value
time[5] = +time[0] < 12 ? ' AM' : ' PM'; // Set AM/PM
time[0] = +time[0] % 12 || 12; // Adjust hours
}
return time.join(''); // return adjusted time or original string
} catch (error) {}
}
import moment from 'moment';
function translate(time) {
try {
const timeSplit = time.split('T');
const date = new Date(timeSplit[0]);
const fullDate = `${date.getDate()} ${
monthNames[date.getMonth()]
} ${date.getFullYear()}`;
const date = moment(time).utcOffset(new Date().getTimezoneOffset() - 120)
const fullDate = moment(date).format('DD MMMM YYYY')
const timeStamp = moment(date).format('hh:mm A')
return `${fullDate}, ${tConvert(timeSplit[1])}`;
return `${fullDate}, ${timeStamp}`;
} catch (error) {}
}
export { tConvert, translate };
export { translate };
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment