覆盖日期格式在.NET中文化 [英] Override date formatting for a culture in .net

查看:131
本文介绍了覆盖日期格式在.NET中文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有内置.NET日期格式存在问题。我们使用的是缩写的月份格式为:

We have a problem with the built-in .net date formatting. We are using the abbreviated month format:

string.Format("{0:MMM}", date);

有关我们的捷克网站,它输出罗马数字(例如IV里的EN-GB这将是月)。我们要改变这一些自定义的缩写。

For our Czech site, it outputs Roman numerals (eg "IV" where in en-GB it would be "Apr"). We want to change this to some custom abbreviations.

什么是做到这一点的最好方法是什么?我真的不希望把一个if语句在视图中。我应该使用的DateTimeFormatInfo?

What is the best way to do this? I don't really want to put an if statement in the view. Should I use a DateTimeFormatInfo?

此外,如何做微软决定的格式,它是基于标准?

Also, how do Microsoft decide on the formatting, is it based on a standard?

推荐答案

哪个文化,你要使用?你只需指定它在调用的String.Format 。例如:

Which culture do you want to use? You can just specify it in the call to string.Format. For example:

string text = string.Format(CultureInfo.InvariantCulture, "{0:MMM}", date);

需要注意的是,如果这是的真正的所有要格式化,它会更简单调用的ToString

Note that if that's really all you're formatting, it would be simpler to call ToString:

string text = date.ToString("MMM", CultureInfo.InvariantCulture);

(这样,你并不需要所有的复合格式化的东西。)

(That way you don't need all the composite formatting stuff.)

这篇关于覆盖日期格式在.NET中文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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