admin管理员组文章数量:1405329
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
1 Answer
Reset to default 5Seems 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);
本文标签: angularSort an array of timestamps in JavaScriptStack Overflow
版权声明:本文标题:angular - Sort an array of timestamps in JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744896926a2631118.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论