-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
711c063
commit 8821b58
Showing
2 changed files
with
31 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Format a date object as YYYY-MM-DD-HH:MM:SS | ||
* Adapted from: | ||
* https://github.com/bobbyhadz/javascript-format-date-yyyy-mm-dd-hh-mm-ss | ||
* @param date Date object to format | ||
* @returns Formatted date as a string | ||
*/ | ||
export const formatDate = (date:Date):string => { | ||
/** | ||
* Pad a number to two digits | ||
* @param num Number to pad | ||
* @returns Modified string | ||
*/ | ||
const padToTwoDigits = (num:number):string => { | ||
return num.toString().padStart(2, '0') | ||
} | ||
return ( | ||
[ | ||
date.getFullYear(), | ||
padToTwoDigits(date.getMonth() + 1), | ||
padToTwoDigits(date.getDate()), | ||
].join('-') + | ||
'-' + | ||
[ | ||
padToTwoDigits(date.getHours()), | ||
padToTwoDigits(date.getMinutes()), | ||
padToTwoDigits(date.getSeconds()), | ||
].join(':') | ||
) | ||
} |
This file contains 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