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

270
Vistas
How to modify date formate in ajax js code?

I have a js ajax code:

success:function(res){
                var _html='';
                var json_data=$.parseJSON(res.posts);
$.each(json_data,function (index,data) {
                        _html+='<span class='time'>'+data.fields.time+'</span>';
                    });
                $(".post-wrapper").append(_html);
}

The issue is the time format is like:

2021-08-05T22:10:55.255Z

How to modify this date formate to something like:

2021-08-05 22:10
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Check out the docs for Moment.js, this should do the trick for you: http://momentjs.com/docs/#/parsing/string+format.

example: <span class='time'>'+moment(data.fields.time).format("YYYY-MM-D HH:mm")+'</span>'

about 4 years ago · Juan Pablo Isaza Denunciar

0

You should be able to just format it within that success function :

var _html='';
var json_data=$.parseJSON(res.posts);
$.each(json_data,function (index,data) { 
    let datetime = data.fields.time;
    let formatted_date = datetime.getFullYear() + "-" + 
    (datetime.getMonth() + 1) + "-" + datetime.getDate() + " " 
    + datetime.getHours() + ":" + datetime.getMinutes();
    _html+='<span class='time'>'+ formatted_date +'</span>';
});
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