【问题标题】:Angular DatePipe Output - show UTC instead of GMTAngular DatePipe 输出 - 显示 UTC 而不是 GMT
【发布时间】:2021-11-12 10:56:05
【问题描述】:

有没有办法可以使用 Angular DatePipe 指定显示“UTC”而不是“GMT”的格式。 示例格式:

{{currentDate | date:'dd/MM/yyyy hh:mm:ss a (O)'}}

输出:17/09/2021 10:50:32 AM (GMT-4)

有没有办法我可以得到以下输出:

输出:17/09/2021 10:50:32 AM (UTC-4)

即在它显示 GMT 的地方,输出应该改为 UTC

【问题讨论】:

    标签: angular utc date-pipe


    【解决方案1】:
    {{ currentDate | date:'dd/MM/yyyy hh:mm:ss a (O)':'UTC' }}
    

    【讨论】:

      【解决方案2】:

      由于这是 purley 演示,并且 GMT 和 UTC 的时间始终相同,您可以创建一个管道:

      @Pipe({
        name: 'utc',
      })
      export class UtcPipe implements PipeTransform {
        transform(dateTime: string): string {
          return dateTime.replace('GMT', 'UTC');
        }
      }
      

      然后是模板:

      {{ currentDate | date: 'dd/MM/yyyy hh:mm:ss a (O)' | utc }}
      

      Stackblitz here.

      上面的答案我也加了,还是不行。

      【讨论】:

        猜你喜欢
        • 2012-07-01
        • 2011-12-26
        • 2011-01-22
        • 2022-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-14
        相关资源
        最近更新 更多