Last active
December 3, 2017 00:26
-
-
Save yayMark/760235db9221a3b7775c2ea3563bdab0 to your computer and use it in GitHub Desktop.
Convert unix epoch to a date time string
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
var args = process.argv.slice(2); | |
var epoch = Number(args[0]); | |
// you can use seconds or milliseconds | |
var length = args[0].toString().length; | |
if (length <= 10) { | |
epoch = epoch * 1000; | |
} | |
var myDate = new Date(epoch); | |
console.log(myDate.toGMTString() + "\nLocal: " + myDate.toLocaleString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I set this up as an alias in .bash_profile with
alias e2d="node ~/projects/epoch_to_date.js"