开发者

Formatting date "day dd/mm/yyyy"

开发者 https://www.devze.com 2023-03-15 11:52 出处:网络
I\'m tr开发者_如何学JAVAying to format a date to look this way: \"day mm/dd/yyyy\" for that I\'m using something like :

I'm tr开发者_如何学JAVAying to format a date to look this way: "day mm/dd/yyyy" for that I'm using something like : "dddd, " + dateFormatInfo.ShortDatePattern The thing is ShortDatePattern does seem to be specific to the current culture info. for example I'm getting: fr_FR : Lundi 27/06/2011 gb_GB : Monday 27/06/2011 when it should be Monday 06/27/2011 I hope I'm being clear.

[Update] I wanted the string to update automatically between "dd/mm/yyyy" and "mm/dd/yyyy" depending on the current culture and i thought ShortDatePattern didn't do the trick but it actually does! it's just that in en_GB it's still "dd/mm/yyyy" [/update]

[Resolved]

DateTime date;

date.ToString("dddd, " + CurrentCultureInfo.DateTimeFormat.ShortDatePattern);


If you always want the date pattern to be MM/dd/yyyy, then specify that:

string format = "dddd, MM/dd/yyyy";

Note that the "/" part is also locale-specific; if you want it to always be a forward-slash, you should escape it:

string format = "dddd, MM'/'dd'/'yyyy";

If that's not what you were looking for, please update your question to make it clear exactly what you're doing (with sample code), the result you're getting, and the result you want.


You can use the following:

DateTime date;
date.ToString("dddd, MM/dd/yyyy");
0

精彩评论

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

关注公众号