开发者

Change date format in razor cshtml view file

开发者 https://www.devze.com 2023-03-31 16:42 出处:网络
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 ti

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号