bitburner-src/utils/helpers/getTimestamp.ts

13 lines
521 B
TypeScript
Raw Normal View History

/**
* Returns a MM/DD HH:MM timestamp for the current time
*/
2021-05-01 09:17:31 +02:00
export function getTimestamp(): string {
const d: Date = new Date();
// A negative slice value takes from the end of the string rather than the beginning.
2021-04-30 05:52:56 +02:00
const stringWidth = -2;
const formattedHours: string = `0${d.getHours()}`.slice(stringWidth);
const formattedMinutes: string = `0${d.getMinutes()}`.slice(stringWidth);
return `${d.getMonth() + 1}/${d.getDate()} ${formattedHours}:${formattedMinutes}`;
}