如何在MVC3中转换日期格式(dd / MM / yyyy) [英] How to convert date format(dd/MM/yyyy) in MVC3
本文介绍了如何在MVC3中转换日期格式(dd / MM / yyyy)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何在foreach循环表(与gridview相同)中转换MVC3中的日期格式(dd / MM / yyyy)?
我的代码如下
Hi all,
How to convert date format(dd/MM/yyyy) in MVC3 in foreach loop Table(Same as gridview)?
My code is as follows
@Html.DisplayFor(modelItem => item.created_date)
谢谢,
Sampath bejugama
Thanks,
Sampath bejugama
推荐答案
而不是使用DisplayFor在div(或任何其他控件)中使用它
Instead of using DisplayFor use this in a div(or any other control)
@item.created_date.ToString("MMM dd yyy")
这是你日期的顶部..
in your model put something like this on the top of your Date..
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString ="{0: d}")]
[Required(ErrorMessage = "Date is required.")]
public DateTime Date { get; set; }
告诉我是否要在创建项目时自动显示日期。我将教你如何
tell me if you want to display the date automatically as you create the item with it.. and I will teach you how
使用这个
@ Html.TextBoxFor(m => m.MktEnquiryDetail.CallbackDate ,{0:dd / MM / yyyy})
Use This
@Html.TextBoxFor(m => m.MktEnquiryDetail.CallbackDate, "{0:dd/MM/yyyy}")
这篇关于如何在MVC3中转换日期格式(dd / MM / yyyy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文