Skip to content

Commit

Permalink
feat: add getNowTimeStr func
Browse files Browse the repository at this point in the history
  • Loading branch information
suressk committed Jul 25, 2022
1 parent 09698d9 commit c1d8974
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/date/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ export const getDayOfYear = (date: Date): number => ~~((date.getTime() - new Dat
* example: getTimeFromDate(new Date()) => '13:06:45'
*/
export const getTimeFromDate = (date: Date): string => date.toTimeString().slice(0, 8)

/**
* Get now time and format to be `xxxx-xx-xx xx:xx:xx`
* @returns
*
* example: getNowTime() => `'2022-07-25 15:18:34'`
*/
export const getNowTimeStr = () => (new Date()).toLocaleString().replaceAll('/', '-')

0 comments on commit c1d8974

Please sign in to comment.