本文整理汇总了C#中System.Globalization.CultureInfo.InvariantCulture属性的典型用法代码示例。如果您正苦于以下问题:C# CultureInfo.InvariantCulture属性的具体用法?C# CultureInfo.InvariantCulture怎么用?C# CultureInfo.InvariantCulture使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Globalization.CultureInfo
的用法示例。
在下文中一共展示了CultureInfo.InvariantCulture属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Globalization;
public class Example
{
public static void Main()
{
// Persist the date and time data.
StreamWriter sw = new StreamWriter(@".\DateData.dat");
// Create a DateTime value.
DateTime dtIn = DateTime.Now;
// Retrieve a CultureInfo object.
CultureInfo invC = CultureInfo.InvariantCulture;
// Convert the date to a string and write it to a file.
sw.WriteLine(dtIn.ToString("r", invC));
sw.Close();
// Restore the date and time data.
StreamReader sr = new StreamReader(@".\DateData.dat");
String input;
while ((input = sr.ReadLine()) != null)
{
Console.WriteLine("Stored data: {0}\n" , input);
// Parse the stored string.
DateTime dtOut = DateTime.Parse(input, invC, DateTimeStyles.RoundtripKind);
// Create a French (France) CultureInfo object.
CultureInfo frFr = new CultureInfo("fr-FR");
// Displays the date formatted for the "fr-FR" culture.
Console.WriteLine("Date formatted for the {0} culture: {1}" ,
frFr.Name, dtOut.ToString("f", frFr));
// Creates a German (Germany) CultureInfo object.
CultureInfo deDe= new CultureInfo("de-De");
// Displays the date formatted for the "de-DE" culture.
Console.WriteLine("Date formatted for {0} culture: {1}" ,
deDe.Name, dtOut.ToString("f", deDe));
}
sr.Close();
}
}
输出:
Stored data: Tue, 15 May 2012 16:34:16 GMT Date formatted for the fr-FR culture: mardi 15 mai 2012 16:34 Date formatted for de-DE culture: Dienstag, 15. Mai 2012 16:34