In software development, the string is parsed as the DateTime object can effectively process and compare the date and time. The following is a method that analyzes the format as "year-month-day: division" in C#as the DateTime object:
Datetime.parse () Method to try to automatically determine the format of the input string and convert it to the Datetime value:
string dateString = "2011-03-21 13:26"; DateTime date = DateTime.Parse(dateString);
If you need to manually specify the format of the input string, you can use datetime.parsexact () method:
<定> Custom format string
string dateString = "2011-03-21 13:26"; string format = "yyyy-MM-dd HH:mm"; DateTime date = DateTime.ParseExact(dateString, format, CultureInfo.InvariantCulture);
More resources
For more guidance on the analysis of string analysis in C#, please refer to the following resources:
The string format in the c#
TryParse () Method
The above is the detailed content of How to Parse 'year-month-day hour:minute' Strings into DateTime Objects in C#?. For more information, please follow other related articles on the PHP Chinese website!