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等

小白云 (80元/月),四川德阳 4核2G,山东枣庄 4核2G,美国VPS20元/月起三网CN2

小白云是一家国人自营的企业IDC,主营国内外VPS,致力于让每一个用户都能轻松、快速、经济地享受高端的服务,成立于2019年,拥有国内大带宽高防御的特点,专注于DDoS/CC等攻击的防护;海外线路精选纯CN2线路,以确保用户体验的首选线路,商家线上多名客服一对一解决处理用户的问题,提供7*24无人全自动化服务。商家承诺绝不超开,以用户体验为中心为用提供服务,一直坚持主打以产品质量用户体验性以及高效...

DiyVM:50元/月起-双核,2G内存,50G硬盘,香港/日本/洛杉矶机房

DiyVM是一家比较低调的国人主机商,成立于2009年,提供VPS主机和独立服务器租用等产品,其中VPS基于XEN(HVM)架构,数据中心包括香港沙田、美国洛杉矶和日本大阪等,CN2或者直连线路,支持异地备份与自定义镜像,可提供内网IP。本月商家最高提供5折优惠码,优惠后香港沙田CN2线路VPS最低2GB内存套餐每月仅50元起。香港(CN2)VPSCPU:2cores内存:2GB硬盘:50GB/R...

RAKsmart:美国圣何塞服务器限量秒杀$30/月起;美国/韩国/日本站群服务器每月189美元起

RAKsmart怎么样?RAKsmart是一家由华人运营的国外主机商,提供的产品包括独立服务器租用和VPS等,可选数据中心包括美国加州圣何塞、洛杉矶、中国香港、韩国、日本、荷兰等国家和地区数据中心(部分自营),支持使用PayPal、支付宝等付款方式,网站可选中文网页,提供中文客服支持。本月商家继续提供每日限量秒杀服务器月付30.62美元起,除了常规服务器外,商家美国/韩国/日本站群服务器、1-10...

cultureinfo为你推荐
chinapay银联在线 银联在线支付 什么区别excel计算公式请教在excel中如何用求和公式waze去国外旅行,哪个APP比较实用视频压缩算法怎样把3个1G多,1个400多MB的视频文件压缩小?但又无损音质和画面清晰度的。at89s52单片机有谁知道单片机如AT89c52,AT89s52具体是指什么含义啊?virusscanvirus scan 是个什么软件?oa办公系统下载OA在哪里下载?印度尼西亚国家代码国际代码jstz举手望,草上马跑,打什么数字?熊猫烧香病毒下载谁知道熊猫烧香病毒
沈阳虚拟主机 网通服务器租用 中国万网虚拟主机 中文域名交易中心 七牛优惠码 表单样式 godaddy域名优惠码 美国php空间 网站被封 ibrs 上海域名 腾讯实名认证中心 美国免费空间 太原网通测速平台 空间登录首页 中国电信测速器 lamp架构 深圳域名 windowsserver2008 赵蓉 更多