最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angular - Sort an array of timestamps in JavaScript - Stack Overflow

programmeradmin3浏览0评论

I am developing an Angular web service for creating photo journeys and displaying them on a map using Leaflet. When I upload the pictures, I get their coordinates from their EXIF data and their DateTimeOriginal from it which returns string like this:

and then save them in array for a further connecting with paths on a map.

I have issues with sorting this array by timestamps in order to connect the markers on the map properly:

How can I sort by time-stamp?

I am developing an Angular web service for creating photo journeys and displaying them on a map using Leaflet. When I upload the pictures, I get their coordinates from their EXIF data and their DateTimeOriginal from it which returns string like this:

and then save them in array for a further connecting with paths on a map.

I have issues with sorting this array by timestamps in order to connect the markers on the map properly:

How can I sort by time-stamp?

Share Improve this question edited May 22, 2018 at 13:08 Cindy Meister 25.7k21 gold badges36 silver badges44 bronze badges asked May 22, 2018 at 12:19 Deyan PeychevDeyan Peychev 873 silver badges7 bronze badges 1
  • 2 Possible duplicate of Sort a string date array – bugs Commented May 22, 2018 at 12:20
Add a ment  | 

1 Answer 1

Reset to default 5

Seems that the dates are invalid. If it would be properly formatted like this ("2012/10/24 16:37:44") you might do this:

const a = new Date("2012/10/24 16:37:44").getTime();

For example, you would map over items in this array

function sortNumber(a,b) {
    return a - b;
}

items.map(item => new Date(item.timestamp).getTime()).sort(sortNumber);
发布评论

评论列表(0)

  1. 暂无评论