csharp Format CultureInfo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Globalization; using System.Text; using System.Threading; namespace sitemapdemo { public partial class FormatStringForm : System.Web.UI.Page { /// <summary> /// http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=vs.71).aspx ///Geovin Du 塗聚文 20120510 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load( object sender, EventArgs e) { // Format a negative integer or floating-point number in various ways. int integralVal = -12345; double floatingVal = -1234.567d; string msgCurrency = "(C) Currency: . . . . . . " ; string msgDecimal = "(D) Decimal:. . . . . . . " ; string msgScientific = "(E) Scientific: . . . . . " ; string msgFixedPoint = "(F) Fixed point:. . . . . " ; string msgGeneral = "(G) General (default):. . " ; string msgNumber = "(N) Number: . . . . . . . " ; string msgPercent = "(P) Percent:. . . . . . . " ; string msgRoundTrip = "(R) Round-trip: . . . . . " ; string msgHexadecimal = "(X) Hexadecimal:. . . . . " ; string msg1 = "Use ToString(String) and the current thread culture.\n" ; string msg2 = "Use ToString(String, IFormatProvider) and a specified culture.\n" ; string msgCulture = "Culture:" ; string msgIntegralVal = "Integral value:" ; string msgFloatingVal = "Floating-point value:" ; CultureInfo ci; Response.Write( "Standard Numeric Format Specifiers:\n" ); // Display the values. Response.Write(msg1+ "<br/>" ); //Thread.CurrentThread.CurrentCulture = new CultureInfo("th-TH", false); // Display the thread current culture, which is used to format the values. ci = Thread.CurrentThread.CurrentCulture; string s=String.Format( "{0,-26}{1}" , msgCulture, ci.DisplayName); Response.Write(s + "<br/>" ); Response.Write(msgCurrency + floatingVal.ToString( "C" ) + "<br/>" ); // Display the integral and floating-point values. s = String.Format( "{0,-26}{1}" , msgIntegralVal, integralVal); Response.Write(s + "<br/>" ); s = String.Format( "{0,-26}{1}" , msgFloatingVal, floatingVal); Response.Write(s + "<br/>" ); //Response.Write(); s = string .Format( "{0:d}" , System.DateTime.Now); ///结果为:2009-3-20 (月份位置不是03) Response.Write(s + "<br/>" ); s = string .Format( "{0:D}" , System.DateTime.Now); //结果为:2009年3月20日 Response.Write(s + "<br/>" ); s = string .Format( "{0:f}" , System.DateTime.Now); //结果为:2009年3月20日 15:37 Response.Write(s + "<br/>" ); s = string .Format( "{0:F}" , System.DateTime.Now); //结果为:2009年3月20日 15:37:52 Response.Write(s + "<br/>" ); s = string .Format( "{0:g}" , System.DateTime.Now); // 结果为:2009-3-20 15:38 Response.Write(s + "<br/>" ); s = string .Format( "{0:G}" , System.DateTime.Now); //结果为:2009-3-20 15:39:27 Response.Write(s + "<br/>" ); s = string .Format( "{0:m}" , System.DateTime.Now); //结果为:3月20日 Response.Write(s + "<br/>" ); s = string .Format( "{0:t}" , System.DateTime.Now); //结果为:15:41 Response.Write(s + "<br/>" ); s = string .Format( "{0:T}" , System.DateTime.Now); //结果为:15:41:50 Response.Write(s + "<br/>" ); // Use the format specifiers that are only for integral types. Response.Write( "Format specifiers only for integral types:" + "<br/>" ); Response.Write(msgDecimal + integralVal.ToString( "D" ) + "<br/>" ); Response.Write(msgHexadecimal + integralVal.ToString( "X" ) + "<br/>" ); // Use the format specifier that is only for the Single and Double // floating-point types. Response.Write( "Format specifier only for the Single and Double types:" + "<br/>" ); Response.Write(msgRoundTrip + floatingVal.ToString( "R" ) + "<br/>" ); ; // Use the format specifiers that are for integral or floating-point types. Response.Write( "Format specifiers for integral or floating-point types:" + "<br/>" ); Response.Write(msgCurrency + floatingVal.ToString( "C" ) + "<br/>" ); Response.Write(msgScientific + floatingVal.ToString( "E" ) + "<br/>" ); Response.Write(msgFixedPoint + floatingVal.ToString( "F" ) + "<br/>" ); Response.Write(msgGeneral + floatingVal.ToString( "G" ) + "<br/>" ); Response.Write(msgNumber + floatingVal.ToString( "N" ) + "<br/>" ); Response.Write(msgPercent + floatingVal.ToString( "P" ) + "<br/>" ); // Display the same values using a CultureInfo object. The CultureInfo class // implements IFormatProvider. Response.Write(msg2); // Display the culture used to format the values. // Create a European culture and change its currency symbol to "euro" because // this particular code example uses a thread current UI culture that cannot // display the euro symbol (€). ci = new CultureInfo( "de-DE" ); ci.NumberFormat.CurrencySymbol = "euro" ; s = String.Format( "{0,-26}{1}" , msgCulture, ci.DisplayName); Response.Write(s + "<br/>" ); Response.Write( "Format specifiers for integral or floating-point types:" + "<br/>" ); Response.Write(msgCurrency + floatingVal.ToString( "C" , ci) + "<br/>" ); // Display the integral and floating-point values. s = String.Format( "{0,-26}{1}" , msgIntegralVal, integralVal); Response.Write(s + "<br/>" ); s = String.Format( "{0,-26}{1}" , msgFloatingVal, floatingVal); Response.Write(s + "<br/>" ); ci = new CultureInfo( "de-DE" ); s = String.Format( "{0,-26}{1}" , msgCulture, ci.DisplayName); Response.Write(s + "<br/>" ); Response.Write( "Format specifiers for integral or floating-point types:" + "<br/>" ); Response.Write(msgCurrency + floatingVal.ToString( "C" , ci) + "<br/>" ); // Display the integral and floating-point values. s = String.Format( "{0,-26}{1}" , msgIntegralVal, integralVal); Response.Write(s + "<br/>" ); s = String.Format( "{0,-26}{1}" , msgFloatingVal, floatingVal); Response.Write(s + "<br/>" ); s = string .Format(CultureInfo.CreateSpecificCulture( "de-DE" ), "{0:d}" , System.DateTime.Now); Response.Write(s + "<br/>" ); s = string .Format(ci, "{0:D}" , System.DateTime.Now); Response.Write(s + "<br/>" ); s = string .Format(ci, "{0:f}" , System.DateTime.Now); Response.Write(s + "<br/>" ); s = string .Format(ci, "{0:F}" , System.DateTime.Now); Response.Write(s + "<br/>" ); s = string .Format(ci, "{0:g}" , System.DateTime.Now); Response.Write(s + "<br/>" ); s = string .Format(ci, "{0:G}" , System.DateTime.Now); Response.Write(s + "<br/>" ); s = string .Format(ci, "{0:m}" , System.DateTime.Now); Response.Write(s + "<br/>" ); s = string .Format(ci, "{0:t}" , System.DateTime.Now); Response.Write(s + "<br/>" ); s = string .Format(ci, "{0:T}" , System.DateTime.Now); Response.Write(s + "<br/>" ); // Use the format specifiers that are only for integral types. Response.Write( "Format specifiers only for integral types:" + "<br/>" ); Response.Write(msgDecimal + integralVal.ToString( "D" , ci) + "<br/>" ); Response.Write(msgHexadecimal + integralVal.ToString( "X" , ci) + "<br/>" ); // Use the format specifier that is only for the Single and Double // floating-point types. Response.Write( "Format specifier only for the Single and Double types:" + "<br/>" ); Response.Write(msgRoundTrip + floatingVal.ToString( "R" , ci) + "<br/>" ); // Use the format specifiers that are for integral or floating-point types. Response.Write( "Format specifiers for integral or floating-point types:" + "<br/>" ); Response.Write(msgCurrency + floatingVal.ToString( "C" , ci) + "<br/>" ); Response.Write(msgScientific + floatingVal.ToString( "E" , ci) + "<br/>" ); Response.Write(msgFixedPoint + floatingVal.ToString( "F" , ci) + "<br/>" ); Response.Write(msgGeneral + floatingVal.ToString( "G" , ci) + "<br/>" ); Response.Write(msgNumber + floatingVal.ToString( "N" , ci) + "<br/>" ); Response.Write(msgPercent + floatingVal.ToString( "P" , ci) + "<br/>" ); ci = new CultureInfo( "de-DE" ); ci.NumberFormat.CurrencySymbol = "euro" ; s = String.Format( "{0,-26}{1}" , msgCulture, ci.DisplayName); Response.Write(s + "<br/>" ); Response.Write( "Format specifiers for integral or floating-point types:" + "<br/>" ); Response.Write(msgCurrency + floatingVal.ToString( "C" , ci) + "<br/>" ); /* Culture Name Culture Identifier Language-Country/Region "" (empty string) 0x007F invariant culture af 0x0036 Afrikaans af-ZA 0x0436 Afrikaans - South Africa sq 0x001C Albanian sq-AL 0x041C Albanian - Albania ar 0x0001 Arabic ar-DZ 0x1401 Arabic - Algeria ar-BH 0x3C01 Arabic - Bahrain ar-EG 0x0C01 Arabic - Egypt ar-IQ 0x0801 Arabic - Iraq ar-JO 0x2C01 Arabic - Jordan ar-KW 0x3401 Arabic - Kuwait ar-LB 0x3001 Arabic - Lebanon ar-LY 0x1001 Arabic - Libya ar-MA 0x1801 Arabic - Morocco ar-OM 0x2001 Arabic - Oman ar-QA 0x4001 Arabic - Qatar ar-SA 0x0401 Arabic - Saudi Arabia ar-SY 0x2801 Arabic - Syria ar-TN 0x1C01 Arabic - Tunisia ar-AE 0x3801 Arabic - United Arab Emirates ar-YE 0x2401 Arabic - Yemen hy 0x002B Armenian hy-AM 0x042B Armenian - Armenia az 0x002C Azeri az-AZ-Cyrl 0x082C Azeri (Cyrillic) - Azerbaijan az-AZ-Latn 0x042C Azeri (Latin) - Azerbaijan eu 0x002D Basque eu-ES 0x042D Basque - Basque be 0x0023 Belarusian be-BY 0x0423 Belarusian - Belarus bg 0x0002 Bulgarian bg-BG 0x0402 Bulgarian - Bulgaria ca 0x0003 Catalan ca-ES 0x0403 Catalan - Catalan zh-HK 0x0C04 Chinese - Hong Kong SAR zh-MO 0x1404 Chinese - Macau SAR zh-CN 0x0804 Chinese - China zh-CHS 0x0004 Chinese (Simplified) zh-SG 0x1004 Chinese - Singapore zh-TW 0x0404 Chinese - Taiwan zh-CHT 0x7C04 Chinese (Traditional) hr 0x001A Croatian hr-HR 0x041A Croatian - Croatia cs 0x0005 Czech cs-CZ 0x0405 Czech - Czech Republic da 0x0006 Danish da-DK 0x0406 Danish - Denmark div 0x0065 Dhivehi div-MV 0x0465 Dhivehi - Maldives nl 0x0013 Dutch nl-BE 0x0813 Dutch - Belgium nl-NL 0x0413 Dutch - The Netherlands en 0x0009 English en-AU 0x0C09 English - Australia en-BZ 0x2809 English - Belize en-CA 0x1009 English - Canada en-CB 0x2409 English - Caribbean en-IE 0x1809 English - Ireland en-JM 0x2009 English - Jamaica en-NZ 0x1409 English - New Zealand en-PH 0x3409 English - Philippines en-ZA 0x1C09 English - South Africa en-TT 0x2C09 English - Trinidad and Tobago en-GB 0x0809 English - United Kingdom en-US 0x0409 English - United States en-ZW 0x3009 English - Zimbabwe et 0x0025 Estonian et-EE 0x0425 Estonian - Estonia fo 0x0038 Faroese fo-FO 0x0438 Faroese - Faroe Islands fa 0x0029 Farsi fa-IR 0x0429 Farsi - Iran fi 0x000B Finnish fi-FI 0x040B Finnish - Finland fr 0x000C French fr-BE 0x080C French - Belgium fr-CA 0x0C0C French - Canada fr-FR 0x040C French - France fr-LU 0x140C French - Luxembourg fr-MC 0x180C French - Monaco fr-CH 0x100C French - Switzerland gl 0x0056 Galician gl-ES 0x0456 Galician - Galician ka 0x0037 Georgian ka-GE 0x0437 Georgian - Georgia de 0x0007 German de-AT 0x0C07 German - Austria de-DE 0x0407 German - Germany de-LI 0x1407 German - Liechtenstein de-LU 0x1007 German - Luxembourg de-CH 0x0807 German - Switzerland el 0x0008 Greek el-GR 0x0408 Greek - Greece gu 0x0047 Gujarati gu-IN 0x0447 Gujarati - India he 0x000D Hebrew he-IL 0x040D Hebrew - Israel hi 0x0039 Hindi hi-IN 0x0439 Hindi - India hu 0x000E Hungarian hu-HU 0x040E Hungarian - Hungary is 0x000F Icelandic is-IS 0x040F Icelandic - Iceland id 0x0021 Indonesian id-ID 0x0421 Indonesian - Indonesia it 0x0010 Italian it-IT 0x0410 Italian - Italy it-CH 0x0810 Italian - Switzerland ja 0x0011 Japanese ja-JP 0x0411 Japanese - Japan kn 0x004B Kannada kn-IN 0x044B Kannada - India kk 0x003F Kazakh kk-KZ 0x043F Kazakh - Kazakhstan kok 0x0057 Konkani kok-IN 0x0457 Konkani - India ko 0x0012 Korean ko-KR 0x0412 Korean - Korea ky 0x0040 Kyrgyz ky-KZ 0x0440 Kyrgyz - Kazakhstan lv 0x0026 Latvian lv-LV 0x0426 Latvian - Latvia lt 0x0027 Lithuanian lt-LT 0x0427 Lithuanian - Lithuania mk 0x002F Macedonian mk-MK 0x042F Macedonian - FYROM ms 0x003E Malay ms-BN 0x083E Malay - Brunei ms-MY 0x043E Malay - Malaysia mr 0x004E Marathi mr-IN 0x044E Marathi - India mn 0x0050 Mongolian mn-MN 0x0450 Mongolian - Mongolia no 0x0014 Norwegian nb-NO 0x0414 Norwegian (Bokml) - Norway nn-NO 0x0814 Norwegian (Nynorsk) - Norway pl 0x0015 Polish pl-PL 0x0415 Polish - Poland pt 0x0016 Portuguese pt-BR 0x0416 Portuguese - Brazil pt-PT 0x0816 Portuguese - Portugal pa 0x0046 Punjabi pa-IN 0x0446 Punjabi - India ro 0x0018 Romanian ro-RO 0x0418 Romanian - Romania ru 0x0019 Russian ru-RU 0x0419 Russian - Russia sa 0x004F Sanskrit sa-IN 0x044F Sanskrit - India sr-SP-Cyrl 0x0C1A Serbian (Cyrillic) - Serbia sr-SP-Latn 0x081A Serbian (Latin) - Serbia sk 0x001B Slovak sk-SK 0x041B Slovak - Slovakia sl 0x0024 Slovenian sl-SI 0x0424 Slovenian - Slovenia es 0x000A Spanish es-AR 0x2C0A Spanish - Argentina es-BO 0x400A Spanish - Bolivia es-CL 0x340A Spanish - Chile es-CO 0x240A Spanish - Colombia es-CR 0x140A Spanish - Costa Rica es-DO 0x1C0A Spanish - Dominican Republic es-EC 0x300A Spanish - Ecuador es-SV 0x440A Spanish - El Salvador es-GT 0x100A Spanish - Guatemala es-HN 0x480A Spanish - Honduras es-MX 0x080A Spanish - Mexico es-NI 0x4C0A Spanish - Nicaragua es-PA 0x180A Spanish - Panama es-PY 0x3C0A Spanish - Paraguay es-PE 0x280A Spanish - Peru es-PR 0x500A Spanish - Puerto Rico es-ES 0x0C0A Spanish - Spain es-UY 0x380A Spanish - Uruguay es-VE 0x200A Spanish - Venezuela sw 0x0041 Swahili sw-KE 0x0441 Swahili - Kenya sv 0x001D Swedish sv-FI 0x081D Swedish - Finland sv-SE 0x041D Swedish - Sweden syr 0x005A Syriac syr-SY 0x045A Syriac - Syria ta 0x0049 Tamil ta-IN 0x0449 Tamil - India tt 0x0044 Tatar tt-RU 0x0444 Tatar - Russia te 0x004A Telugu te-IN 0x044A Telugu - India th 0x001E Thai th-TH 0x041E Thai - Thailand tr 0x001F Turkish tr-TR 0x041F Turkish - Turkey uk 0x0022 Ukrainian uk-UA 0x0422 Ukrainian - Ukraine ur 0x0020 Urdu ur-PK 0x0420 Urdu - Pakistan uz 0x0043 Uzbek uz-UZ-Cyrl 0x0843 Uzbek (Cyrillic) - Uzbekistan uz-UZ-Latn 0x0443 Uzbek (Latin) - Uzbekistan vi 0x002A Vietnamese vi-VN 0x042A Vietnamese - Vietnam */ } } } |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!