Change date format in razor cshtml view file
I need some help that might be easy for all of you out there. I have this mvc3 web app, I just need to convert the display of date format from mm/dd/yyyy hh:mm:ss AM/PM to dd.mm.yyyy HH:MM Military time. I found some solutions but it doesn'开发者_StackOverflow中文版t work like @item.date.ToString("dd.mm.yyyy")
can someone please? Thanks!
Refer to: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx#Y133
This worked for me in a console app:
class Program
{
static void Main(string[] args)
{
//mm/dd/yyyy hh:mm:ss AM/PM to dd.mm.yyyy HH:MM
var date = Convert.ToDateTime("12/13/1980 4:50:34 PM");
Console.WriteLine(date);
var date2 = date.ToString("dd.MM.yyyy HH:mm");
Console.WriteLine(date2);
Console.ReadLine();
}
}
Output:
12/13/1980 4:50:34 PM
13.12.1980 16:50
精彩评论