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

前端 未结 4 1831
无人及你
无人及你 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:13

    If that is a string you receive then you can split the string by T and use only the first part which is the Date component of the whole string and parse that.

    ex:

    string dateTimeAsString = "2012-03-20T14:18:25.000+04:00";
    string dateComponent = dateTimeAsString.Splic('T')[0];
    DateTime date = DateTime.ParseExact(dateComponent, "yyyy-MM-dd",null);
    

提交回复
热议问题