开发者

AM/PM in ASP.NET

开发者 https://www.devze.com 2023-03-04 19:40 出处:网络
I need the time in AM/PM format in an ASP.NET MVC 3 application, and I am using the following statement:

I need the time in AM/PM format in an ASP.NET MVC 3 application, and I am using the following statement:

@Model.ReportDate.ToString("hh:mm tt")

But 开发者_JAVA技巧it is returning 6:45 instead of 6:45 PM. How do I fix this?


The format strings are culture/locale dependent so it may be using the settings from your server (e.g. 24 hour time). Try this:

@Model.ReportDate.ToString("hh:mm tt", 
  System.Globalization.CultureInfo.InvariantCulture)

If this (or something similar) solves your problem, I suggest setting the desired culture in global.asax so your entire app uses the culture you expect.


Depends on the culture:

For cultures that do not use an AM (or PM) designator, this property returns an empty string.

try to use the CultureInfo.InvariantCulture

ToString("hh:mm tt", CultureInfo.InvariantCulture )

It is associated with the English language but not with any country/region.

0

精彩评论

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