import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
/**
* 日期工具類
*/
public class CalendarUtil {
public static final String sf = "yyyyMMdd";
/**
* 將Date 轉換為String類型
* @param date
* @return
* @throws ParseException
*/
public static String getDateToString(Date date, String sdf) throws ParseException {
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
return ft.format(date);
}
/**
* 將String 時間轉成Date
* @param time
* @param sdf
* @return
* @throws ParseException
*/
public static Date getStringToDate(String time,String sdf) throws ParseException{
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
return ft.parse(time);
}
/**
* 將當前時間轉化成String類型
* @param sdf
* @return
*/
public static String getCurrentTime(String sdf) {
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
String t = ft.format(cal.getTime());
return t;
}
/**
* 獲取當年的第一天
* @param year
* @return
*/
public static Date getCurrentYearFirstDay() {
Calendar currCal = Calendar.getInstance();
int currentYear = currCal.get(Calendar.YEAR);
return getYearFirstDay(currentYear);
}
/**
* 獲取某年第一天日期
* @param year 年份
* @return Date
*/
public static Date getYearFirstDay(int year) {
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, year);
Date currYearFirst = calendar.getTime();
return currYearFirst;
}
/**
* 當前時間點
* @return
*/
public static int getCurrentClock(){
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
return hour;
}
public static void main(String[] args) {
System.out.println(CalendarUtil.getCurrentTime("yyyy"));
}
}
public enum DataTypeEnum {
INT("1", "整型"), NUM("2", "數值類型"), PERCENT("3", "百分比類型"), STRING("4", "字符類型");
private String code;
private String msg;
private DataTypeEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
/**
* 數據類型
*/
public String getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
package com.paic.commcc.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.quartz.CronExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.support.CronSequenceGenerator;
/**
*/
public class DateUtil {
public static final String sf = "yyyyMMdd";
public static final String FORMAT_1 = "yyyyMMddHHmmss";
public static final String FORMAT_2 = "YYYY-MM-DD";
public static final String FORMAT_3 = "yyyy年MM月dd日";
public static final String FORMAT_4 = "yyyyMMdd";
public static final String FORMAT_5 = "yyyy-MM-dd";
public static final String FORMAT_6 = "yyyy-MM-dd HH:mm:ss";
public static final String FORMAT_7 = "HH:mm:ss";
public static final String FORMAT_8 = "YYYY/MM/DD";
public static final String FORMAT_9 = "yyyy/MM/dd HH:mm:ss";
public static final String FORMAT_10 = "yyyyMM";
public static final String FORMAT_11 = "yyyyMMdd HH:mm:ss";
public static final String FORMAT_12 = "ss mm HH dd MM ? yyyy";
public static final int CALENDAR_DEFAULT_YEAR = 1990;
public static final int CALENDAR_DEFAULT_MONTH = 1;
public static final int CALENDAR_DEFAULT_DAY = 1;
private static final Logger logger = LoggerFactory.getLogger(DateUtil.class);
private DateUtil() {
}
/**
* 格式化指定的時間
*
* @return String
*/
public static String formatDate(Date date, String format) {
return new SimpleDateFormat(format).format(date);
}
/**
* 將format格式的字符串時間格式化為yyyyMMdd的
*
* @param date
* @param format
* @return
* @throws java.text.ParseException
*/
public static String formatDate(String date, String format) throws ParseException {
return formatDate(parseDate(date, format), FORMAT_4);
}
/**
* 判斷時間格式是否是"yyyyMM"或者"yyyyMMdd"
*
* @param date
* 字符串類型時間
* @param format
* 時間格式
* @return
*/
public static boolean isDate(String date, String format) {
if(StringUtils.isBlank(date) || StringUtils.isBlank(format)) {
return false;
}
if(format.length() != date.length()) {
return false;
}
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date d = sdf.parse(date); // 把字符串轉化為日期(可以過濾掉奇怪格式的日期格式)
String newDate = sdf.format(d);// 日期轉化為字符
/*
* 1,把字符串的日期轉化為Date類型的日期。 2,把Date類型日期轉化為字符串類型日期。 3,如果兩者相等,說明日期格式符合要求
*/
if (null != newDate && newDate.equals(date)) {
return true;
} else {
return false;
}
} catch (ParseException e) {
// 出現異常,說明時間格式有誤
logger.error("時間格式錯誤:{}", e.getMessage(), e);
return false;
}
}
/**
* 格式化當前時間
*
* @return String
*/
public static String formatCurrentDate(String format) {
return formatDate(new Date(), format);
}
/**
* 獲取當前時間戳
*
* @return String
*/
public static String generateSystemTimestamp() {
Date currentDate = new Date();
return String.valueOf(currentDate.getTime());
}
/**
* 獲取當前時間戳
*
* @return String
*/
public static String generateCurrentTimeMillis() {
return String.valueOf(System.currentTimeMillis());
}
/**
* 判斷firstTime是否在secondTime之后,忽略日期部分
*
* @param firstTime
* @param secondTime
* @return
*/
public static boolean isTimeAfter(Date firstTime, Date secondTime) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(firstTime);
calendar1.set(CALENDAR_DEFAULT_YEAR, CALENDAR_DEFAULT_MONTH, CALENDAR_DEFAULT_DAY);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(secondTime);
calendar2.set(CALENDAR_DEFAULT_YEAR, CALENDAR_DEFAULT_MONTH, CALENDAR_DEFAULT_DAY);
return calendar1.after(calendar2);
}
/**
* 判斷firstTime是否在secondTime之前,忽略日期部分
*
* @param firstTime
* @param secondTime
* @return
*/
public static boolean isTimeBefore(Date firstTime, Date secondTime) {
return isTimeAfter(secondTime, firstTime);
}
/**
* 判斷firstTime是否在secondTime之后,不忽略日期部分
*
* @param firstTime
* @param secondTime
* @return
*/
public static boolean isTimeAfterIncludeDate(Date firstTime, Date secondTime) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(firstTime);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(secondTime);
return calendar1.after(calendar2);
}
/**
* 判斷firstTime是否在secondTime之前,不忽略日期部分
*
* @param firstTime
* @param secondTime
* @return
*/
public static boolean isTimeBeforeIncludeDate(Date firstTime, Date secondTime) {
return isTimeAfterIncludeDate(secondTime, firstTime);
}
/**
* 獲取date添加minutes分鍾后的時間
*
* @param date
* @param minutes
* @return
*/
public static Date addMinutes(Date date, int minutes) {
return DateUtils.addMinutes(date, minutes);
}
/**
* 格式化字符串為時間類型
*
* @param date
* @param format
* @return
*/
public static Date parseDate(String date, String format) throws ParseException {
return new SimpleDateFormat(format).parse(date);
}
/**
* 格式化字符串為時間類型(嚴格模式)
*
* @param date
* @param format
* @return
*/
public static Date parseDateStrict(String date, String format) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
dateFormat.setLenient(false);
return dateFormat.parse(date);
}
/**
* 判斷參數的格式是否為“yyyyMMdd”格式的合法日期字符串
*
*/
public static boolean isValidDate(String str) {
try {
if (str != null && !"".equals(str)) {
if (str.length() == 8) {
// 閏年標志
boolean isLeapYear = false;
String year = str.substring(0, 4);
String month = str.substring(4, 6);
String day = str.substring(6, 8);
int vYear = Integer.parseInt(year);
// 判斷年份是否合法
if (vYear < 1900 || vYear > 2200) {
return false;
}
// 判斷是否為閏年
if (vYear % 4 == 0 && vYear % 100 != 0 || vYear % 400 == 0) {
isLeapYear = true;
}
// 判斷月份
// 1.判斷月份
if (month.startsWith("0")) {
String units4Month = month.substring(1, 2);
int vUnits4Month = Integer.parseInt(units4Month);
if (vUnits4Month == 0) {
return false;
}
if (vUnits4Month == 2) {
// 獲取2月的天數
int vDays4February = Integer.parseInt(day);
if (isLeapYear) {
if (vDays4February > 29)
return false;
} else {
if (vDays4February > 28)
return false;
}
}
} else {
// 2.判斷非0打頭的月份是否合法
int vMonth = Integer.parseInt(month);
if (vMonth != 10 && vMonth != 11 && vMonth != 12) {
return false;
}
}
// 判斷日期
// 1.判斷日期
if (day.startsWith("0")) {
String units4Day = day.substring(1, 2);
int vUnits4Day = Integer.parseInt(units4Day);
if (vUnits4Day == 0) {
return false;
}
} else {
// 2.判斷非0打頭的日期是否合法
int vDay = Integer.parseInt(day);
if (vDay < 10 || vDay > 31) {
return false;
}
}
return true;
} else {
return false;
}
} else {
return false;
}
} catch (Exception e) {
logger.error("異常:{}", e.getMessage(), e);
return false;
}
}
/**
* 判斷參數的格式是否為“yyyyMMdd”格式的合法日期字符串
*
*/
public static boolean isValidMonth(String str) {
try {
if (str != null && !"".equals(str)) {
if (str.length() == 6) {
// 閏年標志
String year = str.substring(0, 4);
String month = str.substring(4, 6);
int vYear = Integer.parseInt(year);
// 判斷年份是否合法
if (vYear < 1900 || vYear > 2200) {
return false;
}
// 判斷月份
// 1.判斷月份
if (month.startsWith("0")) {
String units4Month = month.substring(1, 2);
int vUnits4Month = Integer.parseInt(units4Month);
if (vUnits4Month == 0) {
return false;
}
} else {
// 2.判斷非0打頭的月份是否合法
int vMonth = Integer.parseInt(month);
if (vMonth != 10 && vMonth != 11 && vMonth != 12) {
return false;
}
}
return true;
} else {
return false;
}
} else {
return false;
}
} catch (Exception e) {
logger.error("異常:{}", e.getMessage(), e);
return false;
}
}
/**
* 將Date 轉換為String類型
*
* @param date
* @return
* @throws ParseException
*/
public static String getDate2String(Date date, String sdf) {
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
return ft.format(date);
}
public static Date toDate(String str) {
if (str == null) {
return null;
}
try {
str = StringUtils.trim(str);
if (str.indexOf('/') != -1) {
return new SimpleDateFormat("yyyy/MM/dd").parse(str);
}
return new SimpleDateFormat("yyyy-MM-dd").parse(str);
} catch (Exception e) {
// throw new RuntimeException(StringUtils.join("[", str, "] ",
// "DateUtil toDate parse exception"), e);
logger.error(StringUtils.join("[", str, "] ", "DateUtil toDate parse exception"), e.getMessage(), e);
return null;
}
}
/**
* 時間戳轉換成日期格式字符串
*
* @param seconds
* 精確到秒的字符串
* @param format
* @return
*/
public static String timeStamp2Date(String seconds, String format) {
if (seconds == null || seconds.isEmpty() || "null".equals(seconds)) {
return "";
}
SimpleDateFormat sdf;
if (format == null || format.isEmpty()) {
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
} else {
sdf = new SimpleDateFormat(format);
}
return sdf.format(new Date(Long.parseLong(seconds + "000")));
}
/**
* 日期格式字符串轉換成時間戳
*
* @param date_str
* 字符串日期
* @param format
* 如:yyyy-MM-dd HH:mm:ss
* @return
*/
public static String date2TimeStamp(String date_str, String format) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
return String.valueOf(sdf.parse(date_str).getTime() / 1000);
} catch (Exception e) {
logger.error("字符串轉時間戳異常:{}", e.getMessage(), e);
}
return "";
}
/**
* quartz框架時間轉換為timstamp
*
* @param date_str
* 字符串日期
* @param format
* 如:yyyy-MM-dd HH:mm:ss
* @return
*/
public static String date2timeStampForQuartz(String date_str, String format) {
try {
String str = date2TimeStamp(date_str, format);
return str + "000";
} catch (Exception e) {
logger.error("框架時間轉換異常:{}", e.getMessage(), e);
}
return "";
}
/**
* 取得當前時間戳(精確到秒)
*
* @return
*/
public static String timeStamp() {
long time = System.currentTimeMillis();
String t = String.valueOf(time / 1000);
return t;
}
/**
* @param d1
* @param d2
* @return 時間比較, d1 > d2 返回1,d1 < d2 返回-1, d1 = d2 返回0
*/
public static int compareDate(Date d1, Date d2) {
if (d1.getTime() > d2.getTime()) {
return 1;
} else if (d1.getTime() < d2.getTime()) {
return -1;
} else {
return 0;
}
}
/**
* @param m1
* @param m2
* @return 月份比較,返回m1-m2
*/
public static int compareMonth(String m1, String m2) {
if (!isValidMonth(m1) || !isValidMonth(m2)) {
// 不是合法月份,返回999999
return 999999;
} else {
try {
SimpleDateFormat format = new SimpleDateFormat(FORMAT_10);
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(format.parse(m1));
c2.setTime(format.parse(m2));
int month = c1.get(Calendar.MONTH) - c2.get(Calendar.MONTH);
int yearMonth = (c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR)) * 12;
return month + yearMonth;
} catch (ParseException e) {
logger.error("解析異常:{}", e.getMessage(), e);
return 999999;
}
}
}
/**
* @param afterTime
* @param cronExpression
* @return 根據cron表達式獲取某時間之后的下次執行時間
*/
public static Date getTimeAfter(Date afterTime, String cronExpression) {
CronExpression cronEx;
try {
cronEx = new CronExpression(cronExpression);
return cronEx.getTimeAfter(afterTime);
} catch (ParseException e) {
logger.error("根據cron表達式獲取時間異常:{}", e);
return null;
}
}
/**獲取某月的自然天數,2月28天,3月31天
* @taskId <br>
* @param yyyyMM 格式的 validMonth
* @return <br>
*/
public static int countDaysOfMonth(String validMonth){
int year = Integer.parseInt(validMonth.substring(0,4));
int month = Integer.parseInt(validMonth.substring(4));
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month-1);
return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
}
/**
* Description:獲取cron表達式的下次時間 <br>
*
* @author LIYOUHUI784<br>
* @taskId <br>
* @param cronExpression
* @return <br>
*/
public static Date getNextFireTime(String cron) {
if(StringUtils.isBlank(cron)) {
return null;
}
CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron);
return cronSequenceGenerator.next(new Date());
}
/**
* Description:獲取當前月某天某時某分某秒的日歷 <br>
*
* @author liyouhui784<br>
* @taskId <br>
* @param day
* @param hour
* @param minute
* @param second
* @return <br>
*/
public static Calendar getCurrentMonthSomeTime(int day, int hour, int minute, int second) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, second);
return calendar;
}
}
package com.paic.commcc.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
public class DateUtils {
public static final String sf = "yyyyMMdd";
public static final String time_sf = "yyyyMMddHHmmssSSS";
public static final String DATE_FORMAT = "yyyy-MM-dd";
public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String after = "AFTER";
public static final String before = "BEFORE";
/**
* 將linux時間戳 轉換為String類型 date
*
* @param date
* @return
*/
public static Date getLinuxTimeToDate(String dateTime) {
if (dateTime == null) {
return null;
}
Date date = new Date(Long.parseLong(dateTime));
return date;
}
/**
* 將Date 轉換為String類型
*
* @param date
* @return
* @throws ParseException
*/
public static String getDateToString(Date date, String sdf) throws ParseException {
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
return ft.format(date);
}
/**
* 將String 時間轉成Date
*
* @param time
* @param sdf
* @return
* @throws ParseException
*/
public static Date getStringToDate(String time, String sdf) throws ParseException {
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
return ft.parse(time);
}
/**
* 獲取當天使用指定的格式
*/
public static String today(String sdf) {
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
return ft.format(new Date());
}
/**
* 獲取當天使用指定的格式
*/
public static String today() {
return today(sf);
}
/**
* 將當前時間轉化成String類型
*
* @param sdf
* @return
*/
public static String getCurrentTime(String sdf) {
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
String t = ft.format(cal.getTime());
return t;
}
/**
* 獲取當年的第一天
*
* @param year
* @return
*/
public static Date getCurrentYearFirstDay() {
Calendar currCal = Calendar.getInstance();
int currentYear = currCal.get(Calendar.YEAR);
return getYearFirstDay(currentYear);
}
/**
* 獲取某年第一天日期
*
* @param year
* 年份
* @return Date
*/
public static Date getYearFirstDay(int year) {
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, year);
Date currYearFirst = calendar.getTime();
return currYearFirst;
}
/**
* 當前時間點
*
* @return
*/
public static int getCurrentClock() {
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
return hour;
}
/**
* 時間字符串轉時間戳
*
* @throws ParseException
*/
public static String dateToStamp(String s) throws ParseException {
return dateToStamp(s, "yyyy-MM-dd HH:mm:ss");
}
public static String dateToStamp(String s, String sdf) throws ParseException {
String str;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(sdf);
Date date = simpleDateFormat.parse(s);
long ts = date.getTime();
str = String.valueOf(ts);
return str;
}
/**
* 當前時間轉時間戳
*
* @throws ParseException
*/
public static String dateToStamp() {
Date date = new Date();
long ts = date.getTime();
String str = String.valueOf(ts);
return str;
}
/**
* 時間戳轉時間
*/
public static String stampToDate(String s) {
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long ts = Long.parseLong(s);
Date date = new Date(ts);
res = simpleDateFormat.format(date);
return res;
}
/**
* 任意正確時間轉換成為想要的格式字符串
*/
public static String getWantDate(String dateString, String reg) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sb = new SimpleDateFormat(reg);
String s = dateString.replace("-", "").replace(":", "").replace("/", "").replace(" ", "");
String a = s.substring(0, 8);
Date date;
String ss = null;
try {
date = sdf.parse(a);
ss = sb.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
return ss;
}
/**
* 任意正確時間轉換成為想要的日期
*
* @throws ParseException
*/
public static Date getWantDates(String dateString, String reg) throws ParseException {
SimpleDateFormat sb = new SimpleDateFormat("yyyyMMdd");
String str = dateString.replace("-", "").replace(":", "").replace("/", "").replace(" ", "");
String a = str.substring(0, 8);
Date date = sb.parse(a);
return date;
}
/**
* 將String 時間轉成Date
*
* @param time
* @param sdf
* @return
*/
public static Date getString2Date(String time, String sdf) {
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
try {
return ft.parse(time);
} catch (ParseException e) {
// logger.error("字符串轉日期出錯", e);
}
return null;
}
/**
* 將Date 轉換為String類型
*
* @param date
* @return
* @throws ParseException
*/
public static String getDate2String(Date date, String sdf) {
SimpleDateFormat ft = new SimpleDateFormat(StringUtils.isBlank(sdf) ? sf : sdf);
return ft.format(date);
}
/**
* 獲取指定日期的前一天
*
* @param date
* @return
* @throws ParseException
*/
public static Date getYesterDay(Date date, String sdf) throws ParseException {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, -1);
SimpleDateFormat ft = new SimpleDateFormat(sdf);
return ft.parse(ft.format(calendar.getTime()));
}
/**
* 日期計算 目標日期加target天,target為正數表示加,為負數表示減
*
* @param date
* @return Date
* @throws ParseException
*/
public static Date dateCalculate(Date date, String sdf, Integer target) throws ParseException {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, target);
SimpleDateFormat ft = new SimpleDateFormat(sdf);
return ft.parse(ft.format(calendar.getTime()));
}
/**
* 將常用時間格式字符串轉化為時間 - / . 以及沒有分隔都可以
*/
public static Date transformDateStyle(String dateString) {
Date date = null;
if (dateString != null) {
try {
if (dateString.indexOf('-') > 0) {
date = new SimpleDateFormat("yyyy-MM-dd").parse(dateString);
} else if (dateString.indexOf('/') > 0) {
date = new SimpleDateFormat("yyyy/MM/dd").parse(dateString);
} else if (dateString.indexOf('.') > 0) {
date = new SimpleDateFormat("yyyy.MM.dd").parse(dateString);
} else {
date = new SimpleDateFormat("yyyyMMdd").parse(dateString);
}
} catch (ParseException e) {
date = new Date();
}
}
return date;
}
/**
* 判斷輸入的時間是否大於或小於當前日期
*
* @param date
* 需要判斷的日期
* @param str
* AFTER 驗證在當前之前或等於當前日期,BEFORE驗證在當前日期之后或等於當前日期
* @return 1==驗證通過 0==驗證失敗
* @throws ParseException
*/
public static int isDateBeforeOrAfter(Date date, String str) throws ParseException {
Date sdate = new Date();
int dint;
boolean falg;
if (after.equals(str)) {
falg = date.before(sdate);
if (falg) {
return 1;
}
}
if (before.equals(str)) {
dint = date.compareTo(getYesterDay(sdate, sf));
if (dint == 1) {
return 1;
}
}
return 0;
}
/**
* 獲得當月1號零時零分零秒
*
* @return
*/
public static Date initDateByMonth() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return calendar.getTime();
}
}
