Skip to content

Instantly share code, notes, and snippets.

@leejaew
Created September 23, 2013 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leejaew/6676671 to your computer and use it in GitHub Desktop.
Save leejaew/6676671 to your computer and use it in GitHub Desktop.
convert unix timestamp to readable format in javascript
// create a new Date object, foo
var foo = new Date;
// prompt user for a input (e.g. unix timestamp)
//var unixTimestamp = prompt("Enter Unix Timestamp");
// get current system time, getTime()
var unixTimestamp = parseInt(foo.getTime() / 1000);
// call a function in a constructor context
var unixTimeToDate = new Date(unixTimestamp * 1000);
console.log(unixTimeToDate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment