在电子邮件规则中将日期时间字段标记转换为本地时区 [英] Convert DateTime field token to local time zone in email rule

查看:82
本文介绍了在电子邮件规则中将日期时间字段标记转换为本地时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Orchard 中,我有一个包含 DateTime 字段的自定义内容类型.我创建了一个规则,用于在提交新内容项时发送电子邮件.我可以使用以下标记在电子邮件中包含 DateTime 字段的值:

Within Orchard I have a custom content type that includes a DateTime field. I've created a rule to send an email when a new content item is submitted. I'm able to include the value of the DateTime field in the email using the following token:

{Content.Fields.MyContentType.MyDateTimeField}

我遇到的问题是替换令牌的日期/时间值采用 UTC 格式,我需要它位于为我的 Orchard 实例配置的时区中.

The problem I'm running into is that the date/time value that replaces the token is in UTC and I need it to be in the timezone configured for my Orchard instance.

我看到当前日期/时间的标记如下所示:

I see there's a token for the current date/time that looks like this:

{Date.Local}

但是 .Local 似乎对 DateTime 字段标记无效.

But .Local does not seem to be valid on the DateTime field token.

看起来创建一个自定义令牌提供程序来解决这个问题并不太难,但在我这样做之前,我想确保我没有错过一个更简单的现有解决方案.

It looks like it wouldn't be too hard to create a custom token provider to solve for this but before I did that I wanted to make sure I wasn't missing an easier, existing solution.

推荐答案

日期标记确实有一个 Local 子标记,但这里的问题是 {Content.Fields.MyContentType.MyDateTimeField} 不是日期标记,它仍然只是字段.你需要得到它的实际价值.如果您查看 FieldTokens.cs,您会看到日期字段标记有一个 DateTime 标记.所以 {Content.Fields.MyContentType.MyDateTimeField.DateTime.Local} 应该做我认为的把戏.

The date token does indeed have a Local subtoken but the problem here is that {Content.Fields.MyContentType.MyDateTimeField} is not a date token, it's still just the field. You need to get its actual value. If you look at FieldTokens.cs, you'll see that the date field token has a DateTime token. So {Content.Fields.MyContentType.MyDateTimeField.DateTime.Local} should do the trick I think.

这篇关于在电子邮件规则中将日期时间字段标记转换为本地时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆