0

Is there an inbuild DateTime functionality that could give me a string format of today's date as 2020-12-22T13:36:45 Etc/UTC (+00)

I can think of these ways:

var date = DateTime.Now;
var result = date.ToString("yyyy-MM-ddTHH:mm:ss") + " Etc/UTC (+00)";

Console.WriteLine(date.ToString("yyyy-MM-ddTHH:mm:ss Etc/UTC (+00)"));            
//Gives '2020-12-23T10:59:59 EAc/UTC (+00)' - incorrect t replaced by A

Console.WriteLine(result);
//Gives '2020-12-23T10:59:59 Etc/UTC (+00)' Correct, 

As you can see I can get the correct format, though I am not sure this is the best solution, as it looks very artificial.

Is there a better way to format the string?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
YoungDad
  • 765
  • 2
  • 6
  • 14

1 Answers1

1

how about date.ToString("yyyy-MM-ddTHH:mm:ss 'Etc/UTC (+00)'")

or if you need the real timezone, date.ToString("yyyy-MM-ddTHH:mm:ss 'Etc/UTC ('zzz')'")

Mehdi Khademloo
  • 2,754
  • 2
  • 20
  • 40