Created
April 18, 2021 11:07
-
-
Save literakl/77a9ac82eb85002ad3c3890d73166412 to your computer and use it in GitHub Desktop.
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
function timestamp() { | |
const currentDate = new Date(); | |
const day = currentDate.getDate(); | |
const month = currentDate.getMonth() + 1; | |
const year = currentDate.getFullYear(); | |
const hours = currentDate.getHours(); | |
const minutes = currentDate.getMinutes(); | |
const seconds = currentDate.getSeconds(); | |
let ms = currentDate.getMilliseconds(); | |
if (ms < 10) { | |
ms = `00${ms}`; | |
} else if (ms < 100) { | |
ms = `0${ms}`; | |
} | |
return `${year}-${month < 10 ? `0${month}` : month}-${day < 10 ? `0${day}` : day} ${hours < 10 ? `0${hours}` : hours}:${minutes < 10 ? `0${minutes}` : minutes}:${seconds < 10 ? `0${seconds}` : seconds}:${ms}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
primitive solution to get a padded date time
2021-03-08 04:09:09:007
2021-03-28 14:38:23:170