AngularJS 日期时间格式根据本地化获取错误的小时和分钟值

AngularJS datetime format get wrong hour and minute value based on localization

我在数据库中的日期时间值如下

但是下面的 angularJS 代码在视图中显示错误的时间

   <i   title="Baxıldı {{item.ViewedDate | date: 'dd.MM.yyyy hh:mm:ss Z'}}"></i>

例如:

我认为这个错误取决于本地化,在我的国家/地区是 UTC+4,因此当前值增加了 4 小时。

请帮忙解决这个问题。

当您使用 date 过滤器时,您可以添加 timezone 作为第三个参数。

{{ date_expression | date : format : timezone}}

这是一个示例,如果您的数据库中的日期以 UTC 格式存储。

<i   title="Baxıldı {{item.ViewedDate | date: 'dd.MM.yyyy hh:mm:ss Z': 'utc'}}"></i>

来自docs

Timezone to be used for formatting. It understands UTC/GMT and the continental US time zone abbreviations, but for general use, use a time zone offset, for example, '+0430' (4 hours, 30 minutes east of the Greenwich meridian) If not specified, the timezone of the browser will be used.