台灣最大程式設計社群網站
線上人數
861
 
會員總數:243161
討論主題:187981
歡迎您免費加入會員
討論區列表 >> iOS APP/ swift 開發 >> swift 有一串陣列 想要用日期下去排序 求大神解惑
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
swift 有一串陣列 想要用日期下去排序 求大神解惑
價值 : 50 QP  點閱數:445 回應數:0

樓主

nick
門外漢
0 1
4 0
發送站內信

var data =
[(NickName: "", UploadTime: "/Date(1505292562640)/", Account: "weiren", UploadType: "朋友", FileName: "02364444b0e042e5bda683a653ee765d"),
(NickName: "", UploadTime: "/Date(1505292544457)/", Account: "weiren", UploadType: "朋友", FileName: "04e4d2cd51244caf9f40b127cfbe339b"),
(NickName: "", UploadTime: "/Date(1505282582147)/", Account: "weiren", UploadType: "朋友", FileName: "06002d95766f4966a7c291b967edcf17"),
(NickName: "", UploadTime: "/Date(1505282383737)/", Account: "weiren", UploadType: "朋友", FileName: "0bc2e178f48c472091a25afd2441e052"),
(NickName: "", UploadTime: "/Date(1505786084793)/", Account: "weiren", UploadType: "朋友", FileName: "0caa976dac4647afa91071feb106f9c6"),
(NickName: "", UploadTime: "/Date(1505291064337)/", Account: "weiren", UploadType: "朋友", FileName: "0d2c269eca6f4aef8b362bb2ce3aea55"),
(NickName: "", UploadTime: "/Date(1505698299250)/", Account: "weiren", UploadType: "朋友", FileName: "1b3c89777e2045fca829203b04d1256d“)]

=======================================================
func datetodate(date:String) -> String {

var changedate = date.replacingOccurrences(of: "/Date(", with: "").replacingOccurrences(of: ")/", with: "")

let index0 = changedate.startIndex
let index10 = changedate.index(changedate.startIndex, offsetBy: 10)

var time2 = changedate[index0..<index10]

let timeStamp = time2
//轉換為時間
let timeInterval:TimeInterval = TimeInterval(timeStamp)!
let date = NSDate(timeIntervalSince1970: timeInterval)
let dateformatter = DateFormatter()
dateformatter.dateFormat = "yyyy年MM月dd日 HH:mm:ss" //自定義的時間格式
let time = dateformatter.string(from: date as Date)

print("對應時間:"+time)

return time
}
這串可以將UploadTime 轉成時間格式 ex: 2017年09月13日 16:49:22
=======================================================
目前想要依照時間下去做排列 從日期最新的到日期最舊的
可以將data陣列重新排嗎



搜尋相關Tags的文章: [ 陣列 ] , [ 排序 ] , [ swift3 ] , [ ] ,
本篇文章發表於2017-09-20 10:17
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
目前尚無任何回覆
   

回覆
如要回應,請先登入.