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等

ShineServers(5美元/月)荷兰VPS、阿联酋VPS首月五折/1核1G/50GB硬盘/3TB流量/1Gbps带宽

优惠码50SSDOFF 首月5折50WHTSSD 年付5折15OFF 85折优惠,可循环使用荷兰VPSCPU内存SSD带宽IPv4价格购买1核1G50G1Gbps/3TB1个$ 9.10/月链接2核2G80G1Gbps/5TB1个$ 12.70/月链接2核3G100G1Gbps/7TB1个$ 16.30/月链接3核4G150G1Gbps/10TB1个$ 18.10/月链接阿联酋VPSCPU内存SS...

江苏云服务器 2H2G 20M 79元/月 大宽带159元/月 高性能挂机宝6元/月 香港CN2 GIA、美国200G防御 CN2 GIA 折后18元/月 御速云

介绍:御速云成立于2021年的国人商家,深圳市御速信息技术有限公司旗下品牌,为您提供安全可靠的弹性计算服务,随着业务需求的变化,您可以实时扩展或缩减计算资源,使用弹性云计算可以极大降低您的软硬件采购成本,简化IT运维工作。主要从事VPS、虚拟主机、CDN等云计算产品业务,适合建站、新手上车的值得选择,拥有华东江苏、华东山东等国内优质云产品;香港三网直连(电信CN2GIA联通移动CN2直连);美国高...

PIGYUN:美国联通CUVIPCUVIP限时cuvip、AS9929、GIA/韩国CN2机房限时六折

pigyun怎么样?PIGYunData成立于2019年,2021是PIGYun为用户提供稳定服务的第三年,目前商家提供香港CN2线路、韩国cn2线路、美西CUVIP-9929、GIA等线路优质VPS,基于KVM虚拟架构,商家采用魔方云平台,所有的配置都可以弹性选择,目前商家推出了七月优惠,韩国和美国所有线路都有相应的促销,六折至八折,性价比不错。点击进入:PIGYun官方网站地址PIGYUN优惠...

cultureinfo为你推荐
wazeMWC是什么?oa办公系统下载oa办公软件哪里可以下载?自定义表情qq自定义表情awvAWV的转换器 要免费的 看好是AWV不是AMV模式识别算法模式识别的简史部署工具如何使用office2016部署软件微软操作系统下载微软原版xp系统下载网址是哪个啊?有没有免费就可以下载的?审计平台什么是审计工具labelforhtml标签中lable的for属性有什么作用?移动硬盘文件或目录损坏且无法读取急:移动硬盘无法访问,打开提示”文件或目录损坏且无法读取”
抗投诉vps主机 ddos 腾讯云数据库 名片模板psd 500m空间 申请个人网站 老左正传 域名接入 cdn加速原理 流量计费 空间合租 流媒体加速 闪讯官网 服务器是干什么用的 海外空间 云营销系统 中国域名 godaddy空间 服务器硬件配置 葫芦机 更多