Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda