1、在今天的項目中服務器給了一個“2015-12-14T08:43:20.168”類型的時間格式串,我要對他進行識別並且存儲到SQLite中,最後還要利用時間進行查詢和排序。
2、接下來講訴處理步驟
首先、對該類型格式串進行格式化爲Date類型並存儲到數據庫
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss").create().fromJson(str, 類名);
然後、進行查詢
該db爲XUtill中的DBUtil,其中s爲Date類型的變量getTime()得到的數值,orderBy中的Boolean是排序的方式(正序或倒序)
ist<MessageModel> list = db.selector(MessageModel.class)
.where("", "", "")
.and("Time", "<=", s)
.orderBy("EventTime", false)
.limit(30).findAll();