提交 fc19e647 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved performance for reading and writing date and time values.

上级 0381d824
...@@ -32,6 +32,7 @@ public class DateTimeUtils { ...@@ -32,6 +32,7 @@ public class DateTimeUtils {
private static final int DEFAULT_MONTH = 1; private static final int DEFAULT_MONTH = 1;
private static final int DEFAULT_DAY = 1; private static final int DEFAULT_DAY = 1;
private static final int DEFAULT_HOUR = 0; private static final int DEFAULT_HOUR = 0;
private static final int ZONE_OFFSET = Calendar.getInstance().get(Calendar.ZONE_OFFSET);
private static Calendar cachedCalendar = Calendar.getInstance(); private static Calendar cachedCalendar = Calendar.getInstance();
...@@ -424,11 +425,7 @@ public class DateTimeUtils { ...@@ -424,11 +425,7 @@ public class DateTimeUtils {
* @return the milliseconds * @return the milliseconds
*/ */
public static long getTimeLocal(java.util.Date d) { public static long getTimeLocal(java.util.Date d) {
Calendar c = getCalendar(); return d.getTime() + ZONE_OFFSET;
synchronized (c) {
c.setTime(d);
return c.getTime().getTime() + c.get(Calendar.ZONE_OFFSET);
}
} }
/** /**
...@@ -439,12 +436,7 @@ public class DateTimeUtils { ...@@ -439,12 +436,7 @@ public class DateTimeUtils {
* @return the number of milliseconds in GMT * @return the number of milliseconds in GMT
*/ */
public static long getTimeGMT(long millis) { public static long getTimeGMT(long millis) {
Date d = new Date(millis); return millis - ZONE_OFFSET;
Calendar c = getCalendar();
synchronized (c) {
c.setTime(d);
return c.getTime().getTime() - c.get(Calendar.ZONE_OFFSET);
}
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论