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等

ShockHosting($4.99/月),东京机房 可享受五折优惠,下单赠送10美金

ShockHosting商家在前面文章中有介绍过几次。ShockHosting商家成立于2013年的美国主机商,目前主要提供虚拟主机、VPS主机、独立服务器和域名注册等综合IDC业务,现有美国洛杉矶、新泽西、芝加哥、达拉斯、荷兰阿姆斯特丹、英国和澳大利亚悉尼七大数据中心。这次有新增日本东京机房。而且同时有推出5折优惠促销,而且即刻使用支付宝下单的话还可获赠10美金的账户信用额度,折扣相比之前的常规...

老周互联24小时无理由退款,香港原生IP,28元起

老周互联怎么样?老周互联隶属于老周网络科技部旗下,创立于2019年12月份,是一家具有代表性的国人商家。目前主营的产品有云服务器,裸金属服务器。创办一年多以来,我们一直坚持以口碑至上,服务宗旨为理念,为用户提供7*24小时的轮班服务,目前已有上千多家中小型站长选择我们!服务宗旨:老周互联提供7*24小时轮流值班客服,用户24小时内咨询问题可提交工单,我们会在30分钟内为您快速解答!另免费部署服务器...

Ceraus24元/月,国庆促销 香港云上新首月五折

Ceraus数据成立于2020年底,基于KVM虚拟架构技术;主营提供香港CN2、美国洛杉矶CN2、日本CN2的相关VPS云主机业务。喜迎国庆香港上新首月五折不限新老用户,cera机房,线路好,机器稳,适合做站五折优惠码:gqceraus 续费七五折官方网站:https://www.ceraus.com香港云内存​CPU硬盘流量宽带优惠价格购买地址香港云2G2核40G不限5Mbps24元/月点击购买...

cultureinfo为你推荐
orderbydescvf中的order by 3 desc 是什么意思企业资源管理系统企业管理系统有哪些?eagleeye《鹰眼》的男主角是谁?华为总裁女儿为啥姓孟总裁文女主姓孟,女主父母抱错孩子,后来将错就错,养父母对女主很好扫图高清扫图是什么意思,在很多的贴吧里,都有提到一些高清扫图,是自己照杂志上的图片,然后自己再修一下吗搜索引擎的概念什么是搜索引擎?搜索引擎是如何工作的?seo优化技术做seo需要懂什么技术?印度尼西亚国家代码手机上的国家代码是什么jstz泰州哪里有民工市场遗传算法实例求助fortran语言编写的混合遗传算法例子那位大哥大姐有?
怎样申请域名 国外永久服务器 vultr美国与日本 blackfriday uk2 wdcp godaddy 中国特价网 国外网站代理服务器 福建天翼加速 阿里云浏览器 架设服务器 hostker idc是什么 佛山高防服务器 河南移动m值兑换 免费asp空间申请 服务器论坛 阿里云邮箱登陆 域名转入 更多