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

264
Views
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 answers
Answer question

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 Report

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 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!