- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想将 DateTime 格式化为一个字符串,其中包含缩写的月份名称和在图表中的轴标签中使用的日期。
默认的 DateTime 格式字符串不包含缩写的月份。我想没有标准,但我可以采用月份名称的前 3 个字符的子字符串并将其替换为 MonthDay 格式。我会使用 MonthDay 的原因是月份和日期的顺序取决于语言环境。
有没有人有更好的主意?
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#MonthDay
最佳答案
您可以采用 MonthDay
模式并将“MMMM”替换为“MMM”——然后应用该模式:
string pattern = CultureInfo.CurrentCulture.DateTimeFormat.MonthDayPattern;
pattern = pattern.Replace("MMMM", "MMM");
string formatted = dateTime.ToString(pattern);
这有点粗糙,但我相信它会起作用。
关于c# - 如何将日期格式化为本地化的 Short MonthDay 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2787235/
我想将 DateTime 格式化为一个字符串,其中包含缩写的月份名称和在图表中的轴标签中使用的日期。 默认的 DateTime 格式字符串不包含缩写的月份。我想没有标准,但我可以采用月份名称的前 3
这个问题在这里已经有了答案: How to format YearMonth and MonthDay depending on a Locale? (3 个答案) 关闭 5 年前。 我正在尝试格式
我们有一个例子,我们只需要日期和月份,因此将使用 java.time.MonthDay ( Javadocs ) 来表示该信息。 我们知道,我们可以创建自己的 JPA 对象来实现持久性,或者只使用 j
这个问题已经有答案了: How to format YearMonth and MonthDay depending on a Locale? (3 个回答) 已关闭 6 年前。 Java 8 中内置
为什么 YearMonth 类是 Temporal(接口(interface))而 MonthDay 不是 Temporal? 这看起来很奇怪,因为这两个类的含义几乎相同。 我可能会建议永远不要在使用
我是一名优秀的程序员,十分优秀!