如何在mvc 5中更改日期格式 [英] how to change the date format in mvc 5

查看:83
本文介绍了如何在mvc 5中更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi to all,

            here i'm set a field name startdate in textbox but the date format will takes(MM:DD:YYYY) now i want to change (DD:MM:YYYY).can anybody help for this task.

in modal:

[DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> Start_date { get; set; }

IN VIews:-

@Html.TextBoxFor(m => m.Start_date, "{0:dd/MM/yyyy}")

Above code not work for me . Kindly help me please

推荐答案

试试这个:

Try this:
@Html.TextBoxFor(m => m.MyDate, new { Value = Model.MyDate.ToString("DD:MM:YYYY")});





    -Amy



   -Amy


试试这个:

@ Html.TextBoxFor(m => m .MyDateTime,new {Value = Model.MyDateTime.ToString(MM-dd-yyyy),id =MySuperCoolId});







@ Html.TextBox(StartDate,string.Format({0:d},Model.StartDate))
Try this :
@Html.TextBoxFor(m => m.MyDateTime, new { Value = Model.MyDateTime.ToString("MM-dd-yyyy"), id = "MySuperCoolId"});

or

@Html.TextBox("StartDate", string.Format("{0: d}", Model.StartDate))


看到这个链接



如何在MVC3中转换日期格式(dd / MM / yyyy) [ ^ ]


这篇关于如何在mvc 5中更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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