简体   繁体   中英

parse string UTC time back to DateTime

I´m trying to parse string UTC time back to DateTime. Any idea? I´m out of ideas:D.

  private static DataTable FinishFormating(DataTable dataTable)
    {
        DataColumnCollection columns = dataTable.Columns;

        foreach (DataRow row in dataTable.Rows)
        {
            if (columns.Contains("InUseSince"))
            {
                row["InUseSince"].ToString();
                //2019-09-20T00:00:00+02:00
                //    string str = DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'");
                DateTime myDate = DateTime.ParseExact(row[4].ToString(), "yyyy-MM-dd'T'HH:mm:ss.s+zzzzzz",
                                                       System.Globalization.CultureInfo.InvariantCulture);
            }
        }
        return dataTable;
    }

I better think once more guys.. :D

Just troubleshoot it with that line until you get wanted format.

string str = DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:sszzzzzz");

usefull page for that https://support.travelport.com/webhelp/uapi/Content/Getting_Started/Design_Considerations/Date_and_Time_Formats.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM