简体   繁体   English

如何格式化本地时区的MVC3 WebGrid日期列?

[英]How can I format a MVC3 WebGrid date column for local timezone?

My datetime values are stored as UTC in the database. 我的日期时间值以UTC格式存储在数据库中。 I want to display them in the local timezone using the standard MVC3 WebGrid control, but don't have a clue how to do that or where to look for the answer. 我想使用标准的MVC3 WebGrid控件在本地时区中显示它们,但不知道如何执行或在哪里寻找答案。

My current code looks like this: 我当前的代码如下所示:

grid.Column("TestDateTime", "Test Date/Time")

and I know THAT doesn't work! 而且我知道那行不通!

Can somebody steer me in the right direction? 有人可以指引我正确的方向吗? I do have access to the Telerik controls (free from the local user group) but have not tried them as it seems the more add-ons the more hassle (license fees, updates, keeping several dev environments in synch, etc). 我确实可以使用Telerik控件(不受本地用户组的限制),但是还没有尝试使用它们,因为附加件越多,麻烦就越多(许可证费用,更新,保持多个开发环境同步等)。 If it's the only way to go I will do it, but would rather get Microsoft's standard tools to do the job. 如果这是唯一的方法,我会做,但宁愿使用Microsoft的标准工具来完成这项工作。

Thanks, Dave 谢谢戴夫

Try something like : 尝试类似的东西:

grid.Column("DueDate", "Due Date", format: (item) => String.Format("{0:yyyy-MM-dd}", item.DueDate))

you can do pretty much anthing you need afer the format: marker 您可以按照以下格式做几乎所有您需要的事情:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM