how to convert date with 'T' to/from string in C#

前端 未结 4 1829
无人及你
无人及你 2021-01-04 12:57

I used following functions to convert DateTime from/into string:

DATE_OBJ.ToString(DATE_FORMAT);

DateTime.ParseExact(Date_string,          


        
4条回答
  •  再見小時候
    2021-01-04 13:22

    You are better of using DateTimeOffSet like:

    string str = " 2012-03-20T14:18:25.000+04:00";
    DateTimeOffset dto = DateTimeOffset.Parse(str);
    //Get the date object from the string. 
    DateTime dtObject = dto.DateTime; 
    
    //Convert the DateTimeOffSet to string. 
    string newVal = dto.ToString("o");
    

提交回复
热议问题