-
-
Save wanderrful/660b83d459892e304ed2b87285c2d8b6 to your computer and use it in GitHub Desktop.
Print out a nicely formatted timestamp in TypeScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function fn_getTimeStamp(): Object { | |
// Create a date object with the current time | |
let now: Date = new Date(); | |
// Create an array with the current month, day and time | |
let date: Array<String> = [ String(now.getMonth() + 1), String(now.getDate()), String(now.getFullYear()) ]; | |
// Create an array with the current hour, minute and second | |
let time: Array<String> = [ String(now.getHours()), String(now.getMinutes())]; | |
// If seconds and minutes are less than 10, add a zero | |
for (let i of time) { | |
if ( Number(i) < 10 ) { | |
i = "0" + i; | |
} | |
} | |
// Return the formatted string | |
return { | |
date: date.join("/"), | |
time: time.join(":") | |
}; | |
} |
Get Day will return you the workday of the current week (e.g. Monday will always be 1st no matter of its the first or 15th of the month). To get the day of the month you need to use now.getDate()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMO it must be: