Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions src/utils/getTimestamp.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
/**
*
* @param timestamp Timestamp in Epoch Time
* @returns String in form of As of MM/DD/YYYY, HH:mm:SS AM/PM [Date: MM/DD/YYYY]
* @returns String in form of standard time
*/
export const getTimestamp: (timestamp: number) => string = (timestamp) => {
const date = new Date(timestamp);

const year = date.getUTCFullYear().toString();
const month = (date.getUTCMonth() + 1).toString();
const day = date.getUTCDate().toString();
let hour: number | string = date.getUTCHours();
const minute = date.getUTCMinutes().toString().padStart(2, "0");
const second = date.getUTCSeconds().toString().padStart(2, "0");

let ampm = hour > 11 ? "PM" : "AM";
hour = ampm === "PM" ? hour - 12 : hour;
hour = hour.toString().padStart(2, "0");

const monthDayYear = `${month}/${day}/${year}`;
const hourMinuteSecond = `${hour}:${minute}:${second}`;

return `As of ${monthDayYear}, ${hourMinuteSecond} ${ampm} [Date: ${monthDayYear}]`;
};
export const getTimestamp = () => {
let dateTime = new Date()
return `As of ${dateTime}`;
};