-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,754
  • 7
  • 39
  • 73

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
  • 454
  • 3
  • 15
0

You can replace the space with a T:

date.ToString("u").Replace(' ','T');
Peter
  • 27,049
  • 8
  • 63
  • 82