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
  • 94,086
  • 102
  • 195
  • 339
YoungDad
  • 595
  • 2
  • 4
  • 12

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,555
  • 2
  • 15
  • 38