【问题标题】:Format date in SendGrid template portal在 SendGrid 模板门户中格式化日期
【发布时间】:2019-02-19 17:10:25
【问题描述】:

我正在使用 SendGrid 门户来管理我的电子邮件模板,使用把手替换作为此链接中的参考 https://sendgrid.com/docs/ui/sending-email/using-handlebars/#substitution

我想知道是否可以在 SendGrid 交易模板门户中转换和/或格式化日期。

这是我在 SendGrid 门户中的 HTML 模板:

<p>This report was generated on {{GenerationTimeUtc}}</p>

这是发送到 SendGrid 的动态数据:

{
   "GenerationTimeUtc":"2018-09-14T21:16:30.1467851Z"
}

我想以更易读的方式显示它,例如 “此报告于 5 月 4 日生成” 而不是显示 “此报告于 2018-09-14T21:16 生成:30.1467851Z"

我正在使用 SendGrid V3

提前致谢。

【问题讨论】:

  • 不能只发送 json 格式的日期吗?
  • 是的,但这意味着每次用户需要更改日期格式时,我都需要更改我的代码。如果我只能更改模板会更容易

标签: handlebars.js sendgrid


【解决方案1】:

您可以将formatDate 用于这种类型的格式设置,参考标准日期时间格式标志。

<p>Join us {{formatDate dateString "M d"}}</p>

以及使用不同日期格式的类似实现……

<p>Join us {{formatDate dateString "yyyy-mm-dd"}}</p>

【讨论】:

  • 上面列出的链接不再提到formatDate,我在 Handlebars.js 文档中找不到任何对它的引用。 但是,它完全有效,所以我将使用它。
猜你喜欢
  • 2016-03-23
  • 2016-12-09
  • 1970-01-01
  • 2013-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-03
相关资源
最近更新 更多