Closed fxleyu closed 6 years ago
private static final int OFFSET = Calendar.getInstance().getTimeZone().getRawOffset();
private static final long MS_OF_DAY = 1000 * 60 * 60 * 24;
long millisOfToday = (System.currentTimeMillis() + OFFSET) % MS_OF_DAY;
Date
对象
long startTime = TimeUtils.getTimeFromYMDHMSDate(startTimeStr).getTime();
private static final String yearMonthDayHourMiunitSecondFormat = "yyyy-MM-dd HH:mm:ss";
private static final HashMap<String, ThreadLocal<SimpleDateFormat>> formatHashMap = new HashMap<String, ThreadLocal<SimpleDateFormat>>();
public static Date getTimeFromYMDHMSDate(String strTime) {
return getSdf(yearMonthDayHourMiunitSecondFormat).parse(strTime, new ParsePosition(0));
}
private static SimpleDateFormat getSdf(final String pattern) {
ThreadLocal<SimpleDateFormat> sdfThreadLocal = formatHashMap.get(pattern);
if (sdfThreadLocal==null) {
synchronized (lockObj) {
sdfThreadLocal = formatHashMap.get(pattern);
if (sdfThreadLocal==null) {
sdfThreadLocal = new ThreadLocal<SimpleDateFormat>(){
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat(pattern);
}
};
formatHashMap.put(pattern, sdfThreadLocal);
}
}
}
return sdfThreadLocal.get();
现在想到的问题如下:
Date
对象