How to combine two strings (date and time) to a single DateTime

后端 未结 9 1089
刺人心
刺人心 2021-01-17 11:34

I have two strings:

string one = \"13/02/09\";
string two = \"2:35:10 PM\";

I want to combine these two together and convert to a Dat

9条回答
  •  执笔经年
    2021-01-17 11:50

    I had different format and the above answer did not work:

    string one = "2019-02-06";
    string two = "18:30";
    

    The solution for this format is:

    DateTime newDateTime = Convert.ToDateTime(one).Add(TimeSpan.Parse(two));
    

    The result will be: newDateTime{06-02-2019 18:30:00}

提交回复
热议问题