1

I need to convert date format from string to dd/MM/yyyy tt:mm:ss in C# for example convert

string = "2015-07-21T23:00:00.000Z" 

to

{21/07/2015 00:00:00}
Soner Gönül
  • 94,086
  • 102
  • 195
  • 339
K.Z
  • 4,853
  • 23
  • 88
  • 206

1 Answers1

2

I would parse it to DateTime with DateTimeStyles.RoundtripKind enumeration since it is ISO 8601 format then use it's Date property to set it's time part to midnight.

var dt = DateTime.Parse("2015-07-21T23:00:00.000Z", null, DateTimeStyles.RoundtripKind);
Console.WriteLine(dt.Date.ToString("dd'/'MM'/'yyyy HH:mm:ss")); // 21/07/2015 00:00:00

Here a demonstration.

Soner Gönül
  • 94,086
  • 102
  • 195
  • 339