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
  • 97,193
  • 102
  • 206
  • 364
K.Z
  • 5,201
  • 25
  • 104
  • 240

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
  • 97,193
  • 102
  • 206
  • 364