如何格式化日期作为本地化的短MONTHDAY串 [英] How to format a date as localized Short MonthDay string

查看:185
本文介绍了如何格式化日期作为本地化的短MONTHDAY串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想格式化的DateTime包含月份名称缩写,并在图表中的轴标签使用日期的字符串。

I would like to format a DateTime to a string containing the month name abbreviated and the date for use in axis labels in a graph.

默认DateTime格式字符串不包含月份的缩写。我猜是没有标准的,但我可以采取月份名称的前3个字符的子串并替换成MONTHDAY格式的。我会用MONTHDAY的原因是,月份和日期的顺序依赖于语言环境。

The default DateTime format strings do not contain abbreviated month. I guess there is no standard but I could take a substring of the first 3 characters of the month name and replace this into the MonthDay format. The reason I would use MonthDay is that the ordering of month and date is locale dependent.

有没有人有一个更好的主意?

Does anyone have a better idea?

http://msdn.microsoft.com/en-美国/库/ az4se3k1.aspx#MONTHDAY

推荐答案

您可以采取 MONTHDAY 模式和替换MMMM与MMM - 然后应用模式:

You could take the MonthDay pattern and replace "MMMM" with "MMM" - then apply that pattern:

string pattern = CultureInfo.CurrentCulture.DateTimeFormat.MonthDayPattern;
pattern = pattern.Replace("MMMM", "MMM");
string formatted = dateTime.ToString(pattern);



这有点粗糙,但我相信它会的工作。

It's somewhat crude, but I believe it would work.

这篇关于如何格式化日期作为本地化的短MONTHDAY串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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