How to convert date format to date and time?

What is the best way to convert a string to a date and time:

"Jan 7 09:27:56" may also be as follows: "Jan 12 09:27:56"

+4
source share
1 answer

You can use the date and time formatMMM d HH:mm:ss as custom strings in English and uses it :as a TimeSeparatorculture, for example InvariantCulture.

var s = "Jan 7 09:27:56";
DateTime dt = DateTime.ParseExact(s, "MMM  d HH:mm:ss", CultureInfo.InvariantCulture);

or

var s = "Jan 12 09:27:56";
DateTime dt = DateTime.ParseExact(s, "MMM  d HH:mm:ss", CultureInfo.InvariantCulture);
+6
source

Source: https://habr.com/ru/post/1625707/


All Articles