Allen
Allen

Reputation: 3771

format string from Date.getTime()

For some reason I can't find the answer to how to format a string from new Date().getTime().

When I run this string, I get a sequence of numbers such as 1395430135200.

How do I format this back into a readable date with time zone?

Upvotes: 2

Views: 13252

Answers (2)

Daniël Knippers
Daniël Knippers

Reputation: 3055

You need to pass the UNIX time as a parameter to a new date object and can then use .toString() to get a readable interpretation. Like this:

new Date(1395430135200).toString()
// "Fri Mar 21 2014 20:28:55 GMT+0100 (W. Europe Standard Time)"

Upvotes: 5

Joey
Joey

Reputation: 477

Why not just use new Date()?

var now = new Date();
console.log(now.toLocaleDateString());
console.log(now.toLocaleTimeString());

Upvotes: 2

Related Questions