-1

I'm trying to convert my DateTime to the following format:

ex.:

2016-01-13T11:11:11Z

But ToString("u") gives 2016-01-13 11:11:11Z

I need the letter T also between date and time. Is there a way to accomplish this?

Ozkan
  • 3,880
  • 9
  • 47
  • 78

2 Answers2

1

You can supply the T directly in the format like this:

Console.WriteLine(DateTime.Now.ToString("yyyy-MM-ddThh:mm:ssZ"));

This will give you the T and Z you are looking for.

Vahlkron
  • 464
  • 3
  • 15
0

You can replace the space with a T:

date.ToString("u").Replace(' ','T');
Peter
  • 27,590
  • 8
  • 64
  • 84