javascript 带有日期过滤器的 AngularJS UnixTime 到 DateTime 格式失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25534721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:38:34  来源:igfitidea点击:

AngularJS UnixTime to DateTime Format with date filter failed

javascriptangularjsdatetimeunix-timestampangular-filters

提问by Ezeewei

I learned that one can transform a unix time stamp into a date by using date filter from this post: AngularJS. Convert tag value (Unix time to human-readable time)

我了解到可以通过使用这篇文章中的日期过滤器将 unix 时间戳转换为日期: AngularJS。转换标签值(Unix 时间到人类可读的时间)

But I can not convert mine with it...

但我不能用它转换我的......

<td>{{contract.start_date_unix | date:'MM-dd-yyyy'}}</td>

inside the contract.start_date_unix, its valued at 1406779200

在 内contract.start_date_unix,其值为1406779200

I checked it with a checkerthat it shows exactly what I want: Thu, 31 Jul 2014 04:00:00 GMT (but of course, the format I want is MM-dd-yyyy, the date is correct and that's what I try to prove here)

我用检查器检查了它,它显示了我想要的内容:2014 年 7 月 31 日星期四 04:00:00 GMT (当然,我想要的格式是 MM-dd-yyyy,日期是正确的,这就是我尝试的在这里证明)

But when I do the date filter above, it will only show 01-17-1970or 01-16-1970...

但是当我做上面的日期过滤器时,它只会显示01-17-197001-16-1970...

What could be the issue cause this?

这可能是什么问题导致的?

回答by harishr

the time shown is epoch and not actual date. please read the links in your question, answer is there in one of the links.

显示的时间是纪元而不是实际日期。请阅读您问题中的链接,答案在其中一个链接中。

you need to multiply the time by 1000.

您需要将时间乘以 1000。

<td>{{contract.start_date_unix * 1000 | date:'MM-dd-yyyy'}}</td>