I am trying to sort my array.
The array consists of data in time format.
Array:
'9:15 AM', '10:20 AM', '02:15 PM'
How should I sort it ?
I'm getting this data usig json service & using it to list events in jquery mobile's listview . but I want to sort events by time .
UPDATE:
HOW I SORTED DATA FROM JSON BY BOTH DATE AND TIME:
For my particular problem of sorting data got using json by date & time I done like this :
$.getJSON(serviceURL + 'read.php?month_no='+month_no, function(data) {
events = data.data;
events.sort(function(a,b){
a = new Date(a.event_date+' '+a.event_time);
b = new Date(b.event_date+' '+b.event_time);
return a<b?-1:a>b?1:0;
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…