Skip to content

Instantly share code, notes, and snippets.

@yayMark
Last active December 3, 2017 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yayMark/760235db9221a3b7775c2ea3563bdab0 to your computer and use it in GitHub Desktop.
Save yayMark/760235db9221a3b7775c2ea3563bdab0 to your computer and use it in GitHub Desktop.
Convert unix epoch to a date time string
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());
@yayMark
Copy link
Author

yayMark commented Dec 3, 2017

I set this up as an alias in .bash_profile with
alias e2d="node ~/projects/epoch_to_date.js"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment