Convert DateTime field token to local time zone in email rule

早过忘川 提交于 2019-12-11 01:57:17

问题


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}

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}

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.


回答1:


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.



来源:https://stackoverflow.com/questions/13386048/convert-datetime-field-token-to-local-time-zone-in-email-rule

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!