Last active
July 30, 2018 10:55
-
-
Save andreasvirkus/39dde3a11ee64dc8b9dd1f2963d55cd5 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() { | |
var now = new Date(), | |
date = [ now.getMonth() + 1, now.getDate(), now.getFullYear() ], | |
time = [ now.getHours(), now.getMinutes(), now.getSeconds() ]; | |
// Leftpad seconds with 0 | |
for ( var i = 1; i < 3; i++ ) { | |
if ( time[i] < 10 ) { | |
time[i] = "0" + time[i]; | |
} | |
} | |
// Return the formatted string | |
return date.join("/") + " " + time.join(":"); | |
} |
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
// Revisited in 2018 | |
export default () => { | |
const now = new Date() | |
const date = [ | |
now.getMonth() + 1, | |
now.getDate(), | |
now.getFullYear() | |
] | |
let time = [ | |
now.getHours(), | |
now.getMinutes(), | |
now.getSeconds() | |
] | |
// Leftpad time units with 0 | |
time = time.map(t => t < 10 ? '0' + t : t) | |
// Return the formatted string | |
return `${date.join('/')} ${time.join(':')}` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment