The Dateime Parse method adds one day to enter a date.

I am reading the date from an XML file and parsing it in the desired format. It is I who add the day to the date, and I cannot understand why.

: 2014-02-12T15: 21: 19-08: 00 withdrawal: February 13, 2014 01:21

Here is my date parsing code:

string date = DateTime.Parse(row["CountDate"].ToString()).ToString("dd MMM yyyy HH:mm");

Any help would be greatly appreciated.

+3
source share
2 answers

The reason is that the time zone information is used to set the time to the local time zone.

If you remove the suffix "-08: 00", you will find that the time will not be changed. However, you need to know if time zone information is important before ignoring it!

+4
source

, , / UTC 8- , , (Parse ).

/ UTC, .

DateTime.ParseExact("yyyy-MM-ddTHH:mm:ss", row["CountDate"], 
    CultureInfo.InvariantCulture);
+2

All Articles