在文化可变的情况下,格式化不含日期的本地化日期 [英] Formatting a localized date with out the year when the culture is variable

查看:47
本文介绍了在文化可变的情况下,格式化不含日期的本地化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据当前设置的区域性将日期显示为M/dd或dd/M.在我们的应用程序中,我们通过设置显式设置区域性.目前,我们使用以下方法设置日期格式:

I need to have my dates display in the either M/dd or dd/M depending on the currently set culture. With in our app we explicitly set the culture based off config. We currently format our dates using the following method:

string dateStringFormat =Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern;

someDate.ToString(dateStringFormat)

这会产生所需的日期字符串,并格式化为我们的设置区域性(即2013年10月4日或2013年10月4日).但是,当我需要日期不包括年份时,该如何做却仍使其可变?如果我做类似 someDate.ToString("dd/MM",dateStringFormat)之类的事情,那么不管采用哪种文化,都不会总是将其保持为日/月格式吗?希望我的问题很清楚.感谢您提供任何可能的帮助.

This produces the desired date string formatted to our set culture (I.E. 10/4/2013 or 4.10.2013). But in the case when I need the date to not include the year how can I do that and still make it variable? If I do something like someDate.ToString("dd/MM", dateStringFormat) wouldn't that always keep it in day/month format regardless of the culture? Hopefully my question is clear enough. Thanks for any possible help.

推荐答案

尝试使用

将在 zh-CN 文化中输出以下内容:

Will output the following in the en-US culture:

10月04日

以及 pr-BR 文化中的以下内容:

And the following in the pr-BR culture:

4 deoutubro

4 de outubro

这是您可以做的最好的事情,因为可能没有定义的约定将日期的月份和日期部分都显示为数字.

This is the best you can do since there is probably no defined convention for displaying only the month and day portions of a date both as numbers.

这篇关于在文化可变的情况下,格式化不含日期的本地化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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