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

后端 未结 9 1185
刺人心
刺人心 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:53

    The following code will do what you want. I used the UK culture to take care of the d/m/y structure of your date:

            string string1 = "13/2/09";
            string string2 = "2:35:10 PM";
            DateTime combined = DateTime.Parse(string1 + ' ' + string2, new CultureInfo("UK"));
    

提交回复
热议问题