Home > Software design >  I have a DateTime data(like "2021-06-22 17:03:58"),how can i convert it to string(like&quo
I have a DateTime data(like "2021-06-22 17:03:58"),how can i convert it to string(like&quo

Time:12-19

`

  DateTime date = new DateTime(2008, 6, 6, 13, 34, 6);
            string v = date.ToString("HH:mm");
            DateTime Time = DateTime.Parse(v);
            Console.WriteLine(Time);

`

I hope output 13:34,instead of 12/19/2022 13:34:00

CodePudding user response:

Based on what I understand from your code and question: Since you have a complete time format in date, but want to convert it to a string format that only has time and precision, and return the same string to DateTiem because you only have time and precision in string format. you keep, it causes part of your data to be lost, and when you convert it to DatatTiem, the time is no longer the same as the time you entered at the beginning of the code, and the date defaults to today's date. and this is not possible.

  • Related