angular - 使用 Angular 2 管道将时间戳转换为日期

标签 angular typescript timestamp angular-pipe

我正在尝试使用 Angular 管道将 timestamp 转换为日期格式。我在 HTML 模板中写了这个:

{{myTimestamp | date}}

其中 myTimestamp 是数字类型。

我得到了意想不到的结果,例如,时间戳 1468251287(匹配 2016 年 11 月 7 日)显示为 1970 年 1 月 18 日

我想知道如何解决这个问题。

最佳答案

如@Perry 所述,您需要提供以毫秒为单位的日期。来自 date 的 Angular 2 引用我们有:

expression is a date object or a number (milliseconds since UTC epoch) or an ISO string

所以它可以简单地是:

{{load.loadDate * 1000 | date}}

关于angular - 使用 Angular 2 管道将时间戳转换为日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38569832/

相关文章:

angular - 如何将 NgControl 状态传递给 Angular 中的子组件,实现 ControlValueAccessor?

javascript - angular - 基于 mat-select 选项的条件元素

types - 空对象类型和Object有什么区别?

javascript - TS7006 : Parameter 'event' implicitly has an 'any' type

where 子句中的时间戳

Angular 2 - 响应式(Reactive)表单验证消息

angular - Angular 2 中的多个模块

parsing - Google表格等是否可以解析任何全局时间/日期格式?

Angular 8 CLI : Disable differential loading in development serve

java - 获取java sql时间并将其插入到表中