0

I need to make DateTime.Now output a value in this format:

2021-04-01T12:34:56-06:00

What is this format called and how do I achieve it? This part in particular confuses me: -06:00. What is that?

BigBen
  • 46,229
  • 7
  • 24
  • 40
whatwhatwhat
  • 1,991
  • 4
  • 31
  • 50
  • This might be useful https://stackoverflow.com/questions/45835952/vb-net-output-datetime-with-timezone-and-offset – Andrew Mortimer Feb 08 '22 at 16:35
  • I believe that's the time zone? 06:00UTC? – dwirony Feb 08 '22 at 16:36
  • Which are you using vb.net or vba? They are different and the answer will depend on which one you are using. – Scott Craner Feb 08 '22 at 16:36
  • 1
    Take a read of this post [ISO 8601 Datetime understanding](https://stackoverflow.com/questions/51906340/iso-8601-datetime-understanding) it tries to explain just what you are asking. – JayV Feb 08 '22 at 16:37
  • Also (for VBA): https://stackoverflow.com/questions/1600875/how-to-get-the-current-datetime-in-utc-from-an-excel-vba-macro/23968601 – Tim Williams Feb 08 '22 at 16:58
  • It's `DateTime.Now.ToString("O")` without the milliseconds. – Jimi Feb 08 '22 at 17:45
  • You want `DateTime.Now().ToString("yyyy-MM-ddTHH:mm:sszzz")`. The value of `DateTime.Now().Kind.ToString()` is "Local", so it will figure out the zzz part for you. – Andrew Morton Feb 08 '22 at 19:28

0 Answers0