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

122
Vistas
Escaping characters in Luxon formatter

I'm trying to convert duration in seconds using Luxon using the Duration.fromMillis().toFormat().

I want it to output 1d2h for one day and two hours, but I can't escape the d and h.

Here's what I tried so far

Duration.fromMillis(3600 * 26 * 1000).toFormat('d\dh\h')
Duration.fromMillis(3600 * 26 * 1000).toFormat('d[d]h[h]') // Like MomentJS

Both doesn't work

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As already stated by others in the comment, you can use single quotes to escape charcters in luxon, see Escaping secction of the docs:

You may escape strings using single quotes:

DateTime.now().toFormat("HH 'hours and' mm 'minutes'"); //=> '20 hours and 55 minutes'

Here a working example:

const Duration = luxon.Duration;
console.log(Duration.fromMillis(3600 * 26 * 1000).toFormat("d'd'h'h'"));
<script src="https://cdn.jsdelivr.net/npm/luxon@2.3.1/build/global/luxon.min.js"></script>

about 4 years ago · Juan Pablo Isaza 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