cultureinfoSystem.Globalization.CultureInfo 的什么属性或方法 可以把 en-us 显示成English

cultureinfo  时间:2021-06-05  阅读:()

如何处理datetime的时间格式

在.Net Framework 1.1平台下,从个人体验谈谈如何处理日期时间格式。

  1. 默认情况下,DateTime.Now.ToString()的输出与Control Panel中Date/Time的设置格式相关。

  For example, 当Regional Options中Time设置:   Time format: h:mm:ss tt   AM symbol: 上午   PM symbol:下午   Console.WriteLine(DateTime.Now.ToString());   输出结果:12/6/2004 2:37:37 下午   DateTime.Parse("12/6/2004 2:37:37 下午")   OK   // 将日期和时间的指定 String 表示形式转换成其等效的 SqlDateTime   SqlDateTime.Parse("12/6/2004 2:37:37 下午")   Exception:String was not recognized as a valid DateTime.   SqlDateTime.Parse("12/6/2004 2:37:37 PM")   OK   2. 通过DateTime.ToString(string format)方法,使用指定格式format将此实例的值转换成其等效的字符串表示。

  DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")   输出结果:12/06/2004 14:56:37   此时,DateTime的输出格式由format参数控制,与Regional Options中的Date/Time的设置无关。

不过,如果项目中有很多地方需要进行DateTime日期时间格式控制,这样写起来就比较麻烦,虽然可以通过常数const进行控制。

  3. 为当前线程的区域性创建 DateTimeFormatInfo。

  // Sets the CurrentCulture property to U.S. English.   System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);   Console.WriteLine(DateTime.Now.ToString());   输出结果:12/6/2004 2:37:37 PM   若要为特定区域性创建 DateTimeFormatInfo,请为该区域性创建 CultureInfo 并检索 CultureInfo.DateTimeFormat 属性。

  // Creates and initializes a DateTimeFormatInfo associated with the en-US culture.   DateTimeFormatInfo myDTFI = new CultureInfo( "en-US", false).DateTimeFormat;   DateTimeFormatInfo 的实例可以针对特定区域性或固定区域性创建,但不能针对非特定区域性创建。

非特定区域性不提供显示正确日期格式所需的足够信息。

如果试图使用非特定区域性创建 DateTimeFormatInfo 的实例,将发生异常

C# winform国际化

软件行业发展到今天,国际化问题一直都占据非常重要的位置,而且应该越来越被重视。

对于开发人员而言,在编写程序之前,国际化问题是首先要考虑的一个问题,也许有时候这个问题已经在设计者的考虑范围之内,但终归要开发人员去做实现的。

因此,如何实现国际化,是开发人员必须掌握的一项基本技能。

今天,这里要讲的就是,在利用C#进行WinForm开发时,国际化是怎么实现的。

鉴于时间及篇幅关系,这里仅仅介绍一种简单的国际化实现方法,可能这里提到的方法已经有非常多人提到过,但笔者还是不厌其烦地介绍一下。

要在C#中实现国际化,需要相关资源文件,比如要在一个软件中支持英文、中文两种语言,那么就必须有这两种语言的资源文件,这在C#中可以采用资源文件(后缀名为.resx)来实现,我们不妨定义英文资源文件名称为Resource.en-US,中文资源文件名称为Resource.zh-CN,两种资源文件所涉及的ID都应该是一样的(这对于其他更多的资源文件均是一样的),只不过是展示的名称不同罢了。

有了这两种资源文件,接下来就要考虑如何做的问题了。

为了适应多处使用的情形,这里笔者单独编写了一个类ResourceCulture,该类包含了一些静态方法,主要作用是用来设置当前语言及返回当前的语言的相关字符串。

该类代码如下: 01.using System.Reflection; 02.using System.Resources; 03.using System.Threading; 04.using System.Globalization; 05. 06.namespace GlobalizationTest 07.{ 08. class ResourceCulture 09. { 10. /// 11. /// Set current culture by name 12. /// 13. /// name 14. public static void SetCurrentCulture(string name) 15. { 16. if (string.IsNullOrEmpty(name)) 17. { 18. name = "en-US"; 19. } 20. 21. Thread.CurrentThread.CurrentCulture = new CultureInfo(name); 22. } 23. 24. /// 25. /// Get string by id 26. /// 27. /// id 28. /// current language string 29. public static string GetString(string id) 30. { 31. string strCurLanguage = ""; 32. 33. try 34. { 35. ResourceManager rm = new ResourceManager("GlobalizationTest.Resource", Assembly.GetExecutingAssembly()); 36. CultureInfo ci = Thread.CurrentThread.CurrentCulture; 37. strCurLanguage = rm.GetString(id, ci); 38. } 39. catch 40. { 41. strCurLanguage = "No id:" + id + ", please add."; 42. } 43. 44. return strCurLanguage; 45. } 46. } 47.} 在Form1中的代码如下: view plaincopy to clipboardprint? 01./** 02. * This project is just a example to show how to do the globalization in C# winform. 03. * You and rebuild and/or modify it by yourself if you want. 04. * Specially, this project was created in Visual Studio 2010. 05. * 06. * Project Name : GlobalizationTest 07. * Create Date : April 29th, 2010 08. * */ 09. 10.using System; 11.using System.Windows.Forms; 12. 13.namespace GlobalizationTest 14.{ 15. public partial class Form1 : Form 16. { 17. public Form1() 18. { 19. InitializeComponent(); 20. } 21. 22. /// 23. /// Set the resource culture 24. /// 25. private void SetResourceCulture() 26. { 27. // Set the form title text 28. this.Text = ResourceCulture.GetString("Form1_frmText"); 29. 30. // Set the groupbox text 31. this.gbLanguageView.Text = ResourceCulture.GetString("Form1_gbLanguageViewText"); 32. this.gbLanguageSelection.Text = ResourceCulture.GetString("Form1_gbLanguageSelectionText"); 33. 34. // Set the label text 35. this.lblCurLanguageText.Text = ResourceCulture.GetString("Form1_lblCurLanguageText"); 36. this.lblNameText.Text = ResourceCulture.GetString("Form1_lblNameText"); 37. this.lblPhoneText.Text = ResourceCulture.GetString("Form1_lblPhoneText"); 38. 39. // Set the button text 40. this.btnMsgShow.Text = ResourceCulture.GetString("Form1_btnMsgShowText"); 41. 42. // Set radiobutton text 43. this.rbEnglish.Text = ResourceCulture.GetString("Language_EnglishText"); 44. this.rbChinese.Text = ResourceCulture.GetString("Language_ChineseText"); 45. 46. // Set the current language text 47. if (rbEnglish.Checked) 48. { 49. this.lblCurLanguage.Text = ResourceCulture.GetString("Language_EnglishText"); 50. } 51. else if (rbChinese.Checked) 52. { 53. this.lblCurLanguage.Text = ResourceCulture.GetString("Language_ChineseText"); 54. } 55. } 56. 57. private void Form1_Load(object sender, EventArgs e) 58. { 59. // Set the default language 60. ResourceCulture.SetCurrentCulture("en-US"); 61. 62. this.SetResourceCulture(); 63. } 64. 65. private void btnMsgShow_Click(object sender, EventArgs e) 66. { 67. if(string.IsNullOrEmpty(txtName.Text)) 68. { 69. MessageBox.Show(ResourceCulture.GetString("Form1_msgbox_nameText"), ResourceCulture.GetString("Form1_msgbox_TitleText"), 70. MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 71. return; 72. } 73. 74. if (string.IsNullOrEmpty(txtPhone.Text)) 75. { 76. MessageBox.Show(ResourceCulture.GetString("Form1_msgbox_phoneText"), ResourceCulture.GetString("Form1_msgbox_TitleText"), 77. MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 78. return; 79. } 80. 81. MessageBox.Show(ResourceCulture.GetString("Form1_msgbox_InfoText") + txtName.Text + ", " + txtPhone.Text, 82. ResourceCulture.GetString("Form1_msgbox_TitleText"), MessageBoxButtons.OK, MessageBoxIcon.Information); 83. } 84. 85. private void rbEnglish_CheckedChanged(object sender, EventArgs e) 86. { 87. ResourceCulture.SetCurrentCulture("en-US"); 88. this.SetResourceCulture(); 89. } 90. 91. private void rbChinese_CheckedChanged(object sender, EventArgs e) 92. { 93. ResourceCulture.SetCurrentCulture("zh-CN"); 94. this.SetResourceCulture(); 95. } 96. } 97.} 归结起来,要在C#的WinForm中实现国际化,至少需要做好以下几点: (1)准备所需资源文件(如本文中提到的英文和中文资源文件); (2)引入命名空间(包括:System.Reflection、System.Resources、System.Threading和System.Globalization); (3)实例化资源管理器(即ResourceManager); (4)设置当前进程的语言区域; (5)通过资源管理器从指定的资源文件中获取所需值。

通过上述的方法即可简单实现国际化。

自己录制的视频怎么用Silverlight转码

1.先声明一个类并继承 IValueConverter接口 using System.Globalization; using System.Windows.Data; public class DataTimeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime dt = (DateTime)value; return dt.ToLongDateString(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } 2.添加定义的转换器所在的命名空间 xmlns:local="clr-namespace:Bingosoft.PSD.Silverlight.Converters" 3.在资源中声明转换器 4.在控件中进行转换 Binding="{Binding CTime,Converter={StaticResource CTimeConverter}}"

System.Reflection.TargetInvocationException

关键是essException: 对路径“F:jusns3.0_dll编译版JuSNSlibraryjspublic.js”的访问被拒绝。

检查权限,运行这个程序的用户是否有足够的权限访问此文件

C#CultureInfo 和CultureUIInfo的区别

CurrentCulture和CurrentUICulture 设置文化时必须区分用户界面的文化和数字及日期格式的文化。

文化与线程相关, 有了这两种文化类型,就可以把两个文化设置应用于线程。

用线程设置文化时, Thread类提供了属性CurrentCulture和CurrentUICulture。

属性CurrentCulture 用于设置与格式化和排序选项一起使用的文化,而属性CurrentUICulture用于设置用户界面的语言。

使用Windows控制面板中的“区域和语言”选项,用户就可以改变CurrentCulture的默认设置, 如图17-3所示。

使用这个配置,还可以改变文化的默认数字、时间和日期格式。

CurrentUICulture不依赖于这个配置,而依赖于操作系统的语言。

这有一个例外:如果Windows XP或Windows 2000安装了多语言用户 界面(Muti-language User Interface, MUI),就可以用区域配置改变用户界面的语言, 这会影响CurrentUICulture属性。

System.Globalization.CultureInfo 的什么属性或方法 可以把 en-us 显示成English

你要的是这句话吧,System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo( "en-GB"); new一个新的CultureInfo实例,在en-GB下金额使用英镑,还有中文:zh-Cn等

半月湾($59.99/年),升级带宽至200M起步 三网CN2 GIA线路

在前面的文章中就有介绍到半月湾Half Moon Bay Cloud服务商有提供洛杉矶DC5数据中心云服务器,这个堪比我们可能熟悉的某服务商,如果我们有用过的话会发现这个服务商的价格比较贵,而且一直缺货。这里,于是半月湾服务商看到机会来了,于是有新增同机房的CN2 GIA优化线路。在之前的文章中介绍到Half Moon Bay Cloud DC5机房且进行过测评。这次的变化是从原来基础的年付49....

incogne$2.5/月t芬兰VPS,AMD Ryzen、1Gbps带宽

IncogNet LLC是个由3个人运作的美国公司,主要特色是隐私保护,号称绝对保护用户的隐私安全。业务涵盖虚拟主机、VPS等,支持多种数字加密货币、PayPal付款。注册账号也很简单,输入一个姓名、一个邮箱、国家随便选,填写一个邮箱就搞定了,基本上不管资料的真假。当前促销的vps位于芬兰机房,全部都是AMD Ryzen系列的CPU,性能不会差的!5折优惠码:CRYPTOMONTH,支持:BTC,...

易探云:买香港/美国/国内云服务器送QQ音乐绿钻豪华版1年,价值180元

易探云产品限时秒杀&QQ音乐典藏活动正在进行中!购买易探云香港/美国云服务器送QQ音乐绿钻豪华版1年,价值180元,性价比超级高。目前,有四大核心福利产品推荐:福利一、香港云服务器1核1G2M,仅218元/年起(香港CN2线路,全球50ms以内);福利二、美国20G高防云服务器1核1G5M,仅336元/年起(美国BGP线路,自带20G防御);福利三、2G虚拟主机低至58.8元/年(更有免费...

cultureinfo为你推荐
chrome系统谷歌Chrome OS可以用来做什么?数据监测什么是媒体监测?awvawv格式是否等于MP4格式网络电话永久免费打有没有永久免费打电话的网络电话啊?assemblyinfo什么是GAC熊猫烧香病毒下载谁知道熊猫烧香病毒遗传算法实例求助fortran语言编写的混合遗传算法例子那位大哥大姐有?kjava通用KJava是什么意思activitygroupActivityGroup子activity之间的切换效果怎么实现收费视频怎么制作收费视频
北京虚拟主机租用 购买域名和空间 圣迭戈 正版win8.1升级win10 debian6 太原联通测速平台 福建铁通 网通服务器托管 创建邮箱 英雄联盟台服官网 广州虚拟主机 服务器论坛 永久免费空间 腾讯数据库 中国电信宽带测速 免费赚q币 globalsign 以下 g6950 29美元 更多