bitburner-src/utils/helpers/getTimestamp.ts

13 lines
510 B
TypeScript
Raw Normal View History

2018-08-07 05:36:28 +02:00
/**
* Formats the current time (to the minute).
*/
export function getTimestamp() {
const d: Date = new Date();
// A negative slice value takes from the end of the string rather than the beginning.
const stringWidth: number = -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}`;
}