SKLAK
SKLAK

Reputation: 3965

How to convert date format to different date format?

I need to convert the following:

"2015-09-18T19:00:00"

to

"2015/09/18/1900"

I'm able to do this a hacky way by converting the top one to a datetime and then extracting the year,month,day,hour and building the bottom string. Is there a cleaner way to do this?

Upvotes: 1

Views: 56

Answers (2)

Roy
Roy

Reputation: 69

string date = "2015-09-18T19:00:00";
string d= Convert.ToDateTime(date).ToString("yyyy/MM/dd/HHmm");

Upvotes: 1

Maor Veitsman
Maor Veitsman

Reputation: 1564

You can do the following:

var result = DateTime.Parse("2015-09-18T19:00:00").ToString("yyyy/MM/dd/HHmm")

Upvotes: 3

Related Questions