ios 對時間排序

2021-06-06 19:54:07 字數 1559 閱讀 2131

//排序 對時間進行排序

nsmutablearray *dataarray=[[nsmutablearray alloc]initwithcapacity:0];

nsmutabledictionary *dir=[[nsmutabledictionary alloc]init];

[dir setobject:@"2012-12-02" forkey:@"time"];

[dataarray addobject:dir];

[dir release];

nsmutabledictionary *dir1=[[nsmutabledictionary alloc]init];

[dir1 setobject:@"2012-02-15" forkey:@"time"];

[dataarray addobject:dir1];

[dir1 release];

nsmutabledictionary *dir2=[[nsmutabledictionary alloc]init];

[dir2 setobject:@"2012-03-02" forkey:@"time"];

[dataarray addobject:dir2];

[dir2 release];

nsmutabledictionary *dir3=[[nsmutabledictionary alloc]init];

[dir3 setobject:@"2000-03-02" forkey:@"time"];

[dataarray addobject:dir3];

[dir3 release];

nsmutabledictionary *dir4=[[nsmutabledictionary alloc]init];

[dir4 setobject:@"2112-03-02" forkey:@"time"];

[dataarray addobject:dir4];

[dir4 release];

nsmutablearray *myarray=[[nsmutablearray alloc]initwithcapacity:0];

[myarray addobjectsfromarray:dataarray];

//[myarray release];

[dataarray release];

for (int i=0; i<[myarray count]; i++)

nssortdescriptor*sorter=[[nssortdescriptor alloc]initwithkey:@"time" ascending:yes];

nsmutablearray *sortdescriptors=[[nsmutablearray alloc]initwithobjects:&sorter count:1];

nsarray *sortarray=[myarray sortedarrayusingdescriptors:sortdescriptors];

[sorter release];

for (int i=0; i<[sortarray count]; i++)

python list 對時間排序小結。

python list 排序比較簡單。但是對時間排序有時可能會比較麻煩一點,對時間的大致思想是對時間字串進行格式化。然後進行排序。第一種排序方法是按照 的方法進行排序。第二種排序方法比較簡單,但是對時間格式要求比較嚴格。就拿第一種方法中部落格鏈結裡面的result data列表為例吧。因為每個元素的...

對時間的封裝util

將乙個秒數的時間轉成形如00 00 00字串 public static string parsetime string date else else if integer.parseint curday integer.parseint day 2 else else else return da...

SQL 對時間的處理

獲取當前日期 如 yyyy mm dd select datename year,getdate datename month,getdate datename day,getdate 獲取當前日期 如 yyyy mm dd select datename year,getdate datename...