1

プロジェクトにカスタム カルチャを設定しようとしています。しかし、Googleを検索したところ、次のコードが見つかりました。しかし、私はそれにいくつかの問題を抱えています。コメントでそれを観察してください。

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

1 に答える 1

1

DateTime.ToString() メソッドの多くの書式設定値を示すリンクを次に示します。小文字の「r」が言及されていませんが、コードの出力は「R」または「r」と同じようです。

http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx

ファイルに書き込む DateTime 値は、カルチャが変更される前のインバリアント カルチャに基づいています。新しい文化情報を取得する前に、それを書き出して読み返します。

コード以外のどこにも質問がないため、あなたが何を求めているのか推測する必要がありました。あなたが尋ねていることを誤解している場合は、詳細を提供してください。

たぶん、出力を表示する場合は、それが役立つでしょう。

ああ、これは実際に「r」が「R」と同じであると言っているリンクです。これで、質問のその部分のドキュメントができました。

http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

于 2013-10-10T21:34:27.890 に答える