bitburner-src/utils/helpers/getTimestamp.ts
2021-09-04 19:09:30 -04:00

15 lines
493 B
TypeScript

/**
* Returns a MM/DD HH:MM timestamp for the current time
*/
export function getTimestamp(): string {
const d: Date = new Date();
// A negative slice value takes from the end of the string rather than the beginning.
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}`;
}