Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
How can I format a DateTimeOffset to not have a colon in the timezone offset?

I was reading this MSDocs article about DateTime-related format support https://docs.microsoft.com/en-us/dotnet/standard/datetime/system-text-json-support#support-for-the-iso-8601-12019-format

And I was trying to cast datetime to string with this format without colon in the timezone part:

2021-01-01T14:30:10+0030

I want to cast this datetimeoffset to string. I use this format:

yyyy-MM-ddTHH:mm:sszzz

But the output of the ToString("yyyy-MM-ddTHH:mm:sszzz") method is:

2021-01-01T14:30:10+00:30

It has colon (:) sign in timezone part. How can I cast it like '2021-01-01T14:30:10+0030'? (without colon in the timezone part)

Can I format the timezone part?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It seems it's not possible (in .Net 6 at least) to get a format string for DateTimeOffset to get the required representation. However, you can try combining two formats: date (which is of typeDateTimeOffset) and ints Offset (of type TimeSpan)

string result = $"{date:yyyy-MM-ddTHH:mm:sszz}{date.Offset:mm}"; 

Here we combine

  1. date:date:yyyy-MM-ddTHH:mm:sszz - date with Offset up to hours
  2. date.Offset:mm - Offset minutes
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!