【问题标题】:Returning contentful Date & Time as a string not number将内容日期和时间作为字符串而不是数字返回
【发布时间】:2018-10-28 21:05:58
【问题描述】:

我正在尝试使用 contentful 和 angular 5 将博客创建时间添加到我的博客中。我已经使用以下方法返回日期:

<p> Published: {{blog.fields.createdAt}}</p>

但是这会像这样返回:

Published: 2018-05-17

我希望它在哪里返回:

17th May 2018

contentful 中的日期和时间功能设置没有字符串格式选项。有什么我可以在角度上做的事情来改变我吗?

【问题讨论】:

    标签: javascript typescript angular5 blogs contentful


    【解决方案1】:

    查看Angular Docs

    您可以使用角度日期管道。

    <p> Published: {{blog.fields.createdAt | date:'dd LLL yyyy'}}</p>
    

    无法检查,但应该这样做。

    值得注意的是,Angular 没有序数 (th, nd) 的格式选项。你必须实施一些事情来做到这一点。可能创建一个实现 DatePipe 的自定义管道。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-27
      • 1970-01-01
      • 2017-11-26
      • 1970-01-01
      • 1970-01-01
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多