I have the following string: Monday, April 20, 2020 at 9:11 AM
,
How can I convert it into DateTime
object?
What I'm trying:
DateTime myDate = DateTime.ParseExact(
"Monday, April 20, 2020 at 9:11 AM",
"yyyy-MM-dd HH:mm:ss,fff",
System.Globalization.CultureInfo.InvariantCulture);
But as except yyyy-MM-dd HH:mm:ss,fff
not working to this format.
Any suggestions?
Try it here: https://dotnetfiddle.net/uBnqhz
DateTime myDate = DateTime.ParseExact("Monday, April 20, 2020 at 9:20 AM",
"dddd, MMMM dd, yyyy 'at' h:m tt",
System.Globalization.CultureInfo.InvariantCulture);
Please try to use the following format string: "dddd, MMMM d, yyyy 'at' h:mm tt"
.
Also, as suggested in the comments, documentation is your friend.
Here you go
DateTime myDate = DateTime.ParseExact("Monday, April 20, 2020 at 9:11 AM", "dddd, MMMM dd, yyyy 'at' h:mm tt", new System.Globalization.CultureInfo("en"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.