-2

I need to output this string value (2013-05-04 13:12:20.123Z) to a valid Datetime on this format (dd/MM/yyyy HH:mm:ss).

I tried Convert.ToDateTime, DateTime.ParseExact, DateTime.Parse but its change my Hour to another one, actually I tried to understand what is happen under of hood, but I didn't!

Anyone can explain me what the compiler understand about this format? Convert.ToDateTime output the real value of this format?

Which is the best way to Parse it?

4

3 に答える 3

1

日付文字列のZ末尾にある はDateTime.Parse、時刻を UTC として扱うために使用される解析を示します。

つまり、ローカルで解析すると、得られる結果は現地時間になります (-05:00タイムゾーンにいると推測できます.

インスタンスにまったく同じ値が必要な場合は、を使用してリテラルとして扱うことができます。DateTimeParseExactZ

DateTime.ParseExact("2013-05-04 13:12:20.123Z", 
                    "yyyy-MM-dd HH:mm:ss.fff'Z'",
                    CultureInfo.InvariantCulture, 
                    DateTimeStyles.RoundTripKind)

マットのコメントで提案されているようにに変更してくださいDateTimeStuylesRoundTripKind

于 2013-06-07T19:14:40.233 に答える