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等

昔日数据:香港云服务器(2G防御)、湖北云服务器(100G防御),首月5折,低至12元/月

昔日数据,国内商家,成立于2020年,主要销售湖北十堰和香港HKBN的云服务器,采用KVM虚拟化技术构架,不限制流量。当前夏季促销活动,全部首月5折促销,活动截止于8月11日。官方网站:https://www.xrapi.cn/5折优惠码:XR2021湖北十堰云服务器托管于湖北十堰市IDC数据中心,母鸡采用e5 2651v2,SSD MLC企业硬盘、 rdid5阵列为数据护航,100G高防,超出防...

妮妮云(100元/月)阿里云香港BGP专线 2核 4G

妮妮云的来历妮妮云是 789 陈总 张总 三方共同投资建立的网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑妮妮云的市场定位妮妮云主要代理市场稳定速度的云服务器产品,避免新手购买云服务器的时候众多商家不知道如何选择,妮妮云就帮你选择好了产品,无需承担购买风险,不用担心出现被跑路 被诈骗的情况。妮妮云的售后保证妮妮云退款 通过于合作商的友好协商,云服务器提供2天内全额退款,超过2天不退款 物...

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

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

cultureinfo为你推荐
决策树分析什么是决策树法草莓派怎么做草莓派?mac地址克隆怎么克隆MAC地址?企业资源管理系统企业内部管理系统有哪些企业资源管理系统企业人力资源管理系统的重要性?部署工具win10 评估和部署工具包有什么用qq网络硬盘怎么用qq网络硬盘微信智能机器人微信群机器人是怎么实现的单元测试规范单元场景测试是如何进行的?单元测试规范求解,单片机程序的单元测试应该怎么做呢?
免费vps服务器 域名出售 哈尔滨服务器租用 免费域名申请 187邮箱 阿里云搜索 新世界机房 便宜域名 哈喽图床 华为4核 godaddy域名证书 股票老左 双线主机 网通服务器托管 能外链的相册 上海电信测速 阿里云免费邮箱 数据库空间 阿里云手机官网 好看的空间 更多