如何把mongodb中Date日期值转换成本地日期值
1个回答
2016-03-07
展开全部
用了一个函数来处理下:
<pre><code>
public static String toDateStringFromIso(String sdate) {
if ("null".equals(sdate) || "NULL".equals(sdate) || "".equals(sdate) || sdate == null) {
return "";
}
Date d1 = null;
try {
d1 = dateFormaterIsodate.get().parse(sdate);
sharecalendar.setTime(d1);
sharecalendar.set(Calendar.HOUR_OF_DAY,sharecalendar.get(Calendar.HOUR_OF_DAY)+8);
d1=sharecalendar.getTime();
} catch (Exception e) {
e.printStackTrace();
return "";
}
return dateFormater4.get().format(d1);
}
</code></pre>
<pre><code>
public static String toDateStringFromIso(String sdate) {
if ("null".equals(sdate) || "NULL".equals(sdate) || "".equals(sdate) || sdate == null) {
return "";
}
Date d1 = null;
try {
d1 = dateFormaterIsodate.get().parse(sdate);
sharecalendar.setTime(d1);
sharecalendar.set(Calendar.HOUR_OF_DAY,sharecalendar.get(Calendar.HOUR_OF_DAY)+8);
d1=sharecalendar.getTime();
} catch (Exception e) {
e.printStackTrace();
return "";
}
return dateFormater4.get().format(d1);
}
</code></pre>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询