简体   繁体   中英

Angular.js date parsing

I'm working on a project in which I need to implement a list of dates. I have been able to pull the data from the api, however I have been having troubles parsing the format within these dates.

The data that I have been able to pull looks similar to this

[["2015-10-05T13:00:00Z","2015-10-05T21:00:00Z"],
["2015-10-06T13:00:00Z","2015-10-06T21:00:00Z"],
["2015-10-07T13:00:00Z","2015-10-07T21:00:00Z"]] 

Which is sweet that i've been able to pull.....but as you can see, the dates are not really what a user will need.

I've been looking into moment() methods. ( http://momentjs.com/ ) However the problems that i've run into is that the methods that you can use with moment() is that i've only been able to make anything work with one date, not with an array of dates such as what i have.

So my question is, are there any alternatives to moment(), or better ways of parsing an array of dates?

You'd have to loop and parse.. you can do it fairly simply with a .map call (with momentjs ):

var formattedDates = array.map(function(inner) {
    return inner.map(function(d) {
        return moment(d).format("MM/DD/YYYY hh:mm A");
    });
}).reduce(function(p, c) {
    return p.concat(c);
});

Demo: http://jsfiddle.net/6ncpspc0/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM