【问题标题】:Angular - Show datetime without timezone conversionAngular - 显示没有时区转换的日期时间
【发布时间】:2019-11-18 00:33:37
【问题描述】:

我有一个使用这种格式的日期:

this.visited_at: "2019-07-26T10:15:00+0200"

我需要通过忽略时区来显示小时和分钟。

模板:

<p>{{ time.visitedAt | date: 'HH' }} h {{ time.visitedAt | date: 'mm' }}</p>

问题是这会根据机器的时区转换时间。 我需要准确显示 10h15 并忽略所有时区转换。

【问题讨论】:

  • 你必须计算系统时间的增量对吗?

标签: javascript angular datetime


【解决方案1】:

这可能有效(假设您总是会收到相同格式的日期):

visitedAt = '2019-07-26T10:15:00+0200';
timezone = this.visitedAt.substring(this.visitedAt.length - 5); // Get the timezone
<p>{{ visitedAt | date: 'HH \'h\' mm' : timezone }}</p> <!-- Format the date with the timezone you got from the date -->

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 2015-07-15
    • 2011-04-16
    • 2021-01-05
    相关资源
    最近更新 更多