这个问题网上的文档很多,纯粹是记录下来免得以后再找。
Mongo3.4 Java Driver 解决8小时时差问题
String date = "2017-05-26T02:11:11Z";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
sdf.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
Date date2 = sdf.parse(date);
引用:http://lib.csdn.net/snippet/mongodb/61383?knId=1795
public
static
Date mongoDateTran(Date date) {
SimpleDateFormat format =
new
SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss"
);
String dateStr = format.format(date);
format.setCalendar(
new
GregorianCalendar(
new
SimpleTimeZone(
0
,
"GMT"
)));
try
{
return
format.parse(dateStr);
}
catch
(ParseException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
return
date;
}
}