/*
* Copyright (c) 2015, 张涛.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kymjs.blog.utils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import org.kymjs.kjframe.utils.StringUtils;
public class TimeUtils {
private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd");
}
};
public static boolean dateIsTody(String sdate) {
Date time = null;
if (StringUtils.isInEasternEightZones()) {
time = StringUtils.toDate(sdate);
} else {
time = StringUtils.transformTime(StringUtils.toDate(sdate),
TimeZone.getTimeZone("GMT+08"), TimeZone.getDefault());
}
if (time == null) {
return false;
}
String ftime = "";
Calendar cal = Calendar.getInstance();
// 判断是否是同一天
String curDate = dateFormater.get().format(cal.getTime());
String paramDate = dateFormater.get().format(time);
return curDate.equals(paramDate);
}
}