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

357
Views
¿Cómo formatear fechas en JavaScript específicamente?

Tengo una fecha en el siguiente formato 2019-01-02T03:04:05 y me gustaría convertirla y mostrarla en la interfaz de usuario de esta manera: 3 de enero de 2019. No estoy muy seguro de qué formato se llama y cómo convertir en el formato deseado como este: 3rd of Jan 2019 .

¿Alguien sabe cómo lograr esto? Estoy usando JavaScript y React para manejar esta lógica.

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

Para formatear fechas, es más fácil (y también es una buena práctica) usar una biblioteca, como moment.js o similar.

 moment('your date here').format('output format here (read moment.js docs and see an examles)'); moment().format('MMMM Do YYYY, h:mm:ss a'); // June 13th 2022, 10:26:03 am

Para tu caso:

 moment('2019-01-02T03:04:05').format('Do [of] MMM YYYY'); // 2nd of Jan 2019

tienes el 2nd de enero, no el 3rd de enero.

about 4 years ago · Santiago Gelvez Report

0

Puede formatear usando la biblioteca date-fns

const date = "2019-01-02T03:04:05";

format(new Date(date), "do 'of' MMM yyyy"); // 2nd of Jan 2019

Opciones de formato: https://date-fns.org/v2.28.0/docs/format

about 4 years ago · Santiago Gelvez Report

0

Estoy de acuerdo con @Sergej .

Para formatear fechas, es más fácil (y también es una buena práctica) usar una biblioteca, como moment.js o similar.

Pero si desea crear sus propias funciones, creo que podría usar esto.

 function formatDate(date) { const d = new Date(date); const day = d.getDate(); const month = d.toLocaleString('default', { month: 'short' }); const year = d.getFullYear(); return `${ordinal(day)} of ${month} ${year}`; } function ordinal(day) { const suffixes = ['th', 'st', 'nd', 'rd']; const mod100 = day % 100; const suffix = (mod100 >= 11 && mod100 <= 13) ? 'th' : suffixes[(day % 10 < 4) ? (day % 10) : 0]; return `${day}${suffix}`; } console.log(formatDate("2019-01-02T03:04:05")) //Output: '2nd of Jan 2019'
about 4 years ago · Santiago Gelvez 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!