Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 设置自己的区域性或更改datetime的当前区域性_C#_Cultureinfo - Fatal编程技术网

C# 设置自己的区域性或更改datetime的当前区域性

C# 设置自己的区域性或更改datetime的当前区域性,c#,cultureinfo,C#,Cultureinfo,我正在尝试在我的项目中设置自定义区域性。但我有一些问题,我搜索了谷歌,找到了下面的代码。但我有一些问题,请在评论中观察 using System; using System.IO; using System.Globalization; public class Example { public static void Main() { // Persist the date and time data. StreamWriter sw =

我正在尝试在我的项目中设置自定义区域性。但我有一些问题,我搜索了谷歌,找到了下面的代码。但我有一些问题,请在评论中观察

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));//what r mean?. if r is the custem culture      variabel then how we determin it.
        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));// f?

            // 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();
    }
}

下面的链接显示了DateTime.ToString()方法的许多格式值。我没有看到提到小写字母“r”,但代码的输出似乎与“r”或“r”相同

写入文件的日期时间值将基于任何区域性更改之前的不变区域性。在获得一些新的文化信息之前,你把它写出来,然后再读回

我不得不猜测你在问什么,因为除了代码之外,没有其他问题。如果我误解了你的问题,请提供更多细节

如果你能展示你的成果,也许会有所帮助

啊,这里有一个链接,实际上说“r”和“r”是一样的。现在你已经有了关于你问题那一部分的文档:


这里有一个链接,显示了DateTime.ToString()方法的许多格式值。我没有看到提到小写字母“r”,但代码的输出似乎与“r”或“r”相同

写入文件的日期时间值将基于任何区域性更改之前的不变区域性。在获得一些新的文化信息之前,你把它写出来,然后再读回

我不得不猜测你在问什么,因为除了代码之外,没有其他问题。如果我误解了你的问题,请提供更多细节

如果你能展示你的成果,也许会有所帮助

啊,这里有一个链接,实际上说“r”和“r”是一样的。现在你已经有了关于你问题那一部分的文档:


您阅读了Microsoft的大量文档吗?@slaks是的,我从那里复制了此文档。您是否收到任何错误/异常,如果有,它们是什么?@sam当我将其更改为其他类似“a”的内容时,此抛出异常声明“输入字符串的格式不正确”。@Irfan:格式说明符在不同文化中是相同的;每一个都将为该区域性使用适当的格式。您阅读了Microsoft的大量文档吗?@slaks是的,我从那里复制了此文档。您是否收到任何错误/异常,如果是,它们是什么?@sam当我将其更改为其他类似“a”的内容时,此抛出异常声明“输入字符串格式不正确”@Irfan:不同文化中的格式说明符是相同的;每个人都将针对该文化使用适当的格式。