最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - format string from Date.getTime() - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question asked Mar 21, 2014 at 22:31 AllenAllen 3,77110 gold badges42 silver badges60 bronze badges 1
  • 2 Have you really tried to find an answer? – Teemu Commented Mar 21, 2014 at 22:35
Add a ment  | 

2 Answers 2

Reset to default 5

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)"

Why not just use new Date()?

var now = new Date();
console.log(now.toLocaleDateString());
console.log(now.toLocaleTimeString());
发布评论

评论列表(0)

  1. 暂无评论