我想基于用户设置的文化信息在我的应用程序上设置日期和时间的格式,但是,我看到的每个帮助资源都不断提示我必须手动输入每个文化语言环境的代码。例如,如果我想要英国,我将不得不手动添加新的CultureInfo(“en-UK”);像新文化信息(“en-UK”);。基于WP7上的文化信息转换日期和时间
有没有一种方法可以轻松进入手机当前设定的文化,而不必实际输入rtc文化信息?可能会像“日期= ConvertToLocalCultureFormat(日期);”?
我想基于用户设置的文化信息在我的应用程序上设置日期和时间的格式,但是,我看到的每个帮助资源都不断提示我必须手动输入每个文化语言环境的代码。例如,如果我想要英国,我将不得不手动添加新的CultureInfo(“en-UK”);像新文化信息(“en-UK”);。基于WP7上的文化信息转换日期和时间
有没有一种方法可以轻松进入手机当前设定的文化,而不必实际输入rtc文化信息?可能会像“日期= ConvertToLocalCultureFormat(日期);”?
我不知道,如果这个工程上WinPhone7,但你可以使用
CultureInfo.CurrentCulture.Name
其返回当前线程的的CurrentCulture的名称(EN-UK或任何你的应用程序运行在)
然而,这不应该是必要的。 如果您的时间值转换为字符串以这种方式:
DateTime dt = DateTime.Now;
// Converts dt, formatted using the ShortDatePattern
// and the CurrentThread.CurrentCulture.
string dateInString = dt.ToString("d");
你应该在你的手机右侧的CultureInfo转换。
您阅读过哪些帮助资源,建议您必须手动指定当前文化?
DateTime.ToString()
无参数方法自动使用从当前文化派生的格式化信息。
此方法使用从当前文化派生的格式化信息。特别是,它组合了由
Thread.CurrentThread.CurrentCulture.DateTimeFormat
属性返回的DateTimeFormatInfo
对象的ShortDatePattern
和LongTimePattern
属性返回的自定义格式字符串。
DateTime exampleDate = new DateTime(2008, 5, 1, 18, 32, 6);
string s = exampleDate.ToString();
// Gives "5/1/2008 6:32:06 PM" when the current culture is en-US.
// Gives "01/05/2008 18:32:06" when the current culture is fr-FR.
// Gives "2008/05/01 18:32:06" when the current culture is ja-JP.
要使用当前区域性格式化任何东西,你没有做什么特别的。不包含特定格式或文化的所有格式的重载使用默认文化。
例如Date.ToString()
方法会调用过载this.ToString(CultureInfo.CurrentCulture)
来获取应用程序的当前文化设置并用于格式化。
谢谢,我认为它可能需要设置,否则,因为我读过一些抱怨说它默认为en-US的文章。 – Euthyphro