long date = 1468758769761L; Date isoDate = new Date(date); FindIterable<Document> findIterable = collection.find(gt("upLineDate", isoDate)).batchSize(1000);
在Mongodb中時間的存儲格式為ISODate,如下所示,ISODate時間表示格林尼治時間,而我們通常需要看的時間是我們的東八區時間
"offLineDate" : ISODate("2016-07-18T00:20:59.248Z"),
"upLineDate" : ISODate("2016-07-18T00:20:41.529Z"),
在java mongoDB driver獲取的時候,API內部其實已經作了轉換,從ISODate---》Date, 具體可參考如下這篇文章
http://blog.csdn.net/doctor_who2004/article/details/50449561
while (mongoCursor.hasNext()) { Document doc = mongoCursor.next(); Date tempDate = doc.getDate("upLineDate"); System.out.println(df.format(tempDate)); //2016-07-18 12:01:22 本地時間 }
