英語の日付をドイツ語に変換しようとしましたが、フォーマットが正しくありません。Convert english正確な構文解析の日付
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
DateTime currentCultureDate = DateTime.Now;
string format = "dd.MM.yyyy HH:mm:ss";
Console.WriteLine("Format: " + format);
Console.WriteLine("Original Date: " + currentCultureDate);
DateTime convertedDate = DateTime.ParseExact(currentCultureDate.ToString(), format, new CultureInfo("de-DE"));
Console.WriteLine("Converted Date: " + convertedDate);
FormatException .....
'ParseExact'を使用していますが、' 'dd.MM.yyyy HH:mm:ss" 'という形式を期待していますが、' currentCultureDate.ToString() 'で使用しています。その形式ではないので、 'FormatException'を返します。 – Equalsk
しかし、私はtoString()を使ってそれを変換したので、datetimeがなくなり、正しいフォーマットになりました – mty
そうではありません。 'currentCultureDate.ToString()'を表示し、そのフォーマットを見てください。 '/'で区切られています。 '.'でフォーマットを指定すると、エラーが発生します... – Equalsk