Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a readable date and time from a string?

Tags:

c#

.net

datetime

I'm using an api that returns the date as a string, like so:

2011-06-13T21:15:19Z

As you can imagine this is not the easiest format to understand. My goal is to get it to format like this:

9:15pm - 6/13/2011

Anyone know how to accomplish this? Do I need to use a regular expression or is there a way to convert this to a DateTime?

NOTE: I have tried to use the DateTime.ParseExact method but it didn't work. If this is the solution could you please show me how to convert the example above. Thanks.

like image 388
Edward Avatar asked Dec 29 '25 02:12

Edward


1 Answers

string date = "2011-06-13T21:15:19Z";
DateTime dt = DateTime.Parse(date);
like image 71
Xaisoft Avatar answered Dec 31 '25 17:12

Xaisoft