我如何格式化日期时间显示为只是在剃刀生成视图一天中的时间? [英] How do I format a DateTime to be displayed as simply the time of day in a Razor-generated view?

查看:147
本文介绍了我如何格式化日期时间显示为只是在剃刀生成视图一天中的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提供位于model.StartDate在以下code一个完整的日期时间:

I am supplying a full DateTime located at model.StartDate in the following code:

@Html.DisplayFor(model => model.StartDate.ToString("hh:mm tt"),
CultureInfo.CreateSpecificCulture("hu-HU"));

我的目标是把完整的日期时间

My goal is to take the full DateTime

8/30/2012 11:33:48 AM

和只显示

11:33:48 AM

不过,我得到以下错误:

however, I get the following error:

Templates can be used only with field access, property access,
single-dimension array index, or single-parameter custom indexer expressions.

为什么这个错误发生?

Why is this error happening?

注:我引用本文档格式化我的ToString我的日期时间: HTTP ://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Note: I referenced this documentation to format my .ToString for my DateTime: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

推荐答案

您可以把DataAnnotation你的模型类。事情是这样的 - > [DisplayFormat(DataFormatString ={0:D},ApplyFormatInEditMode = TRUE)]

You can put a DataAnnotation on your model class. Something like this -> [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)].

这篇关于我如何格式化日期时间显示为只是在剃刀生成视图一天中的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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