java 对日期的运算操作


package com.ilantu.common.date;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

public class DateUtil implements Serializable{

public static final TimeZone NewYorkTimeZone = TimeZone.getTimeZone("America/New_York");
public static final TimeZone CSTTimeZone = TimeZone.getTimeZone("CST");
public static final TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");
public static final TimeZone HKTimeZone = TimeZone.getTimeZone("Asia/Hong_Kong");
public static final TimeZone SHTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
public static final TimeZone KRCHTimeZone = TimeZone.getTimeZone("Asia/Karachi");
public static final TimeZone PRCTimeZone = TimeZone.getTimeZone("PRC");
public static final TimeZone CTTTimeZone = TimeZone.getTimeZone("CTT");
public static final TimeZone MSTTimeZone = TimeZone.getTimeZone("MST");
public static final TimeZone PSTTimeZone = TimeZone.getTimeZone("PST");
public static final TimeZone ASTTimeZone = TimeZone.getTimeZone("AST");
public static final TimeZone ESTTimeZone = TimeZone.getTimeZone("EST");

/**
* Java Default DateFormat string for Application.
*/
public static final String DATEFORMAT = "EEE MMM dd hh:mm:ss z yyyy";
/**
* Default Dateformat string for System Administration
*/
public static final String DEFAULT_ADMIN_DATE_FORMAT="yyyy-MM-dd HH:mm:ss";
/**
* Default Dateformat string for System
*/
public static final String DEFAULT_SYSTEM_DATE_FORMAT="yyyy-MM-dd HH:mm:ss.SSS";
/**
* Default Dateformat string for Bisiness
*/
public static final String DEFAULT_BIZ_DATE_FORMAT="yyyy-MM-dd";

/**
* Default FSCS Date formatter
*/
public static final SimpleDateFormat DATEFORMATTER = new SimpleDateFormat(DATEFORMAT);

/**
* Basic System Date formatter for innternal transfer.but not for presentation
*/
public static final SimpleDateFormat SYSTEM_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
/**
* basic FSCS Date formatter.
*/
public static final SimpleDateFormat FSCS_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
/**
* Default FSCS Business Date formatter
*/
public static final SimpleDateFormat FSCS_BIZ_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
/**
* Basic FSCS Short Date formatter
*/
public static final SimpleDateFormat FSCS_SHORT_DATE_FORMATTER = new SimpleDateFormat("yy-MM-dd");
/**
* Basic FSCS Admin Date formatter
*/
public static final SimpleDateFormat FSCS_ADMIN_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* YYYYMMDD FSCS Date formatter
*/
public static final SimpleDateFormat YYYYMMDD_FORMATTER = new SimpleDateFormat("yyyyMMdd");

/**
* Short YYYYMMDD FSCS Date formatter
*/
public static final SimpleDateFormat YYMMDD_FORMATTER = new SimpleDateFormat("yyMMdd");
/**
* Full Date format as yyyy-MM-dd HH:mm:ss
*/
public static final SimpleDateFormat YYYY_MM_DD_HH_MM_SS_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final SimpleDateFormat YYYYMMDDHHMMSS_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");



/**
* RMS limit Date formatter?
*/
public static final SimpleDateFormat YYYY_MMM_DD_HH_MM_SS_FORMATTER = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
/**
* YYYYMMMDD FSCS Date formatter
*/
public static final SimpleDateFormat YYYY_MMM_DD_FORMATTER = new SimpleDateFormat("yyyy-MMM-dd");

/**
* DDMMMYYYY FSCS Date formatter
*/
public static final SimpleDateFormat DD_MMM_YYYY_FORMATTER = new SimpleDateFormat("dd-MMM-yyyy");

/**
* in the future, the param will be put into config.xml
*/
private static String currentDbms = "ORACLE";
/**
* get GMT mean Time.
* @return java.util.Date
* @deprecated
*/
public static final Date getGMTTimeStamp() {
/*long zoneOffset = fromZone.getRawOffset() - GMTTimeZone.getRawOffset();
return new Date((date.getTime() - zoneOffset));*/
return toDate(new Date(), DateUtil.GMTTimeZone);
}

/**
* get GMT mean Time.
* @return java.sql.Timestamp
*/
public static final Date getGMTTimestamp() {
return toDate(new Date(), DateUtil.GMTTimeZone);
}

public static final Timestamp getGMTSqlTimestamp() {
return new java.sql.Timestamp(getGMTTimestamp().getTime());
}


public static final Date toDate(Date date, TimeZone timeZone) {
Date dt = null;
try {
String ds = toString(date, timeZone);
dt = FSCS_DATE_FORMATTER.parse(ds);
} catch (ParseException ex) {

}
return dt;
}


public static final Date toDate(Date date, TimeZone fromZone, TimeZone toZone) {
long zoneOffset = fromZone.getRawOffset() - toZone.getRawOffset();
return new Date((date.getTime() - zoneOffset));
}

public static final Date toDate(String dateStr) {
Date date = null;
if(dateStr==null||dateStr.trim().length()==0){
return null;
}
try {
date = SYSTEM_DATE_FORMATTER.parse(dateStr);
} catch (ParseException ex) {

}
if(date==null){
try {
date = FSCS_ADMIN_DATE_FORMATTER.parse(dateStr);
} catch (ParseException ex) {

}
}
if(date==null) {
try {
Locale loc=null;
loc=Locale.getDefault();
SimpleDateFormat sysFormatter=(SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,loc);
date = sysFormatter.parse(dateStr);
} catch (ParseException ex) {

}
}
return date;
}


public static final Date toDate(String dateStr,String format) {
Date date = null;
if(dateStr==null||dateStr.trim().length()==0){
return null;
}
if(format==null||format.trim().length()==0){
format=DEFAULT_ADMIN_DATE_FORMAT;
}
SimpleDateFormat formatter = new SimpleDateFormat(format);
try {
date = formatter.parse(dateStr);
} catch (ParseException ex) {

}
if(date==null){
formatter = new SimpleDateFormat(DEFAULT_SYSTEM_DATE_FORMAT);
try {
date = formatter.parse(dateStr);
} catch (ParseException ex) {

}
}
if(date==null) {
try {
Locale loc=null;
loc=Locale.getDefault();
SimpleDateFormat sysFormatter=(SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,loc);
date = sysFormatter.parse(dateStr);
} catch (ParseException ex) {

}
}
return date;
}


public static final Date toDate(String dateStr,SimpleDateFormat formatter) {
Date date = null;
if(dateStr==null||dateStr.trim().length()==0){
return null;
}
try {
date = formatter.parse(dateStr);
} catch (ParseException ex) {

}
if(date==null) {
try {
Locale loc=null;
loc=Locale.getDefault();
SimpleDateFormat sysFormatter=(SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,loc);
date = sysFormatter.parse(dateStr);
} catch (ParseException ex) {

}
}
return date;
}


public static final Date toBizDate(String dateStr){
Date date = null;
if(dateStr==null||dateStr.trim().length()==0){
return null;
}
try {
date = FSCS_BIZ_DATE_FORMATTER.parse(dateStr);
} catch (ParseException ex) {

}
if(date==null) {
try {
Locale loc=null;
loc=Locale.getDefault();
SimpleDateFormat sysFormatter=(SimpleDateFormat)DateFormat.getDateInstance(DateFormat.MEDIUM,loc);
date = sysFormatter.parse(dateStr);

} catch (ParseException ex) {

}
}
return date;
}

public static final Date toShortDate(String dateStr) {
Date date = null;
if(dateStr==null||dateStr.trim().length()==0){
return null;
}
try {
date = FSCS_SHORT_DATE_FORMATTER.parse(dateStr);
} catch (ParseException ex) {

}
if(date==null) {
try {
Locale loc=null;
loc=Locale.getDefault();
SimpleDateFormat sysFormatter=(SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT,loc);
date = sysFormatter.parse(dateStr);
} catch (ParseException ex) {

}
}
return date;
}

public static final Date toSqlTimestamp(String dateStr) {
return new java.sql.Timestamp(toDate(dateStr).getTime());
}
public static Date toSqlTimestamp(String dateStr,String format) {
return new java.sql.Timestamp(toDate(dateStr,format).getTime());
}

public static String toString(Date date) {
return FSCS_ADMIN_DATE_FORMATTER.format(date);
}


public static final String toString(Date date, String format) {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat(format);
formatter.setCalendar(calendar);
return formatter.format(date);
}

public static final String toString(Date date, SimpleDateFormat formatter) {
Calendar calendar = Calendar.getInstance();
formatter.setCalendar(calendar);
return formatter.format(date);
}


public static final String toString(Date date, TimeZone timeZone) {
return toString(date, timeZone, SYSTEM_DATE_FORMATTER);
}


public static final String toString(Date date, TimeZone timeZone, String format) {
Calendar calendar = Calendar.getInstance(timeZone);
SimpleDateFormat formatter = new SimpleDateFormat(format);
formatter.setCalendar(calendar);
return formatter.format(date);
}

public static String toString(Date date, TimeZone timeZone, SimpleDateFormat formatter) {
Calendar calendar = Calendar.getInstance(timeZone);
formatter.setCalendar(calendar);
return formatter.format(date);
}

public static final String toBizString(Date date) {
return FSCS_BIZ_DATE_FORMATTER.format(date);
}


public static String toBizString(Date date,String format) {
String dateStr = null;
if(format==null||format.trim().length()==0){
format=DEFAULT_BIZ_DATE_FORMAT;
}
SimpleDateFormat formatter = new SimpleDateFormat(format);
dateStr = formatter.format(date);
return dateStr;
}

public static final String toShortString(Date date) {
return FSCS_SHORT_DATE_FORMATTER.format(date);
}



public static final int calculateDays(Date date1, Date date2) {
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(date1);
c2.setTime(date2);
long days = (c1.getTime().getTime() - c2.getTime().getTime() + (60*60*1000L))/(60*60*1000L*24);
return (new Long(days)).intValue();
}


public static final boolean isBetweenDates(Date date1,Date date2,Date date){
if(date.getTime()<=date2.getTime() && date.getTime()>=date1.getTime()){
return true;
}
else{
return false;
}
}

public static final boolean isBetweenDates2(Date date1,Date date2,Date date){
if(date.getTime()<date2.getTime() && date.getTime()>date1.getTime()){
return true;
}
else{
return false;
}
}

public static final boolean isWeekend(Date date) {
Calendar cal = new GregorianCalendar();
cal.setTime(date);
if ((cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
|| (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)) {
return true;
}
return false;
}

public static final boolean isWeekday(Date date) {
return !isWeekend(date);
}


public static final boolean isBeforeByDay(Date date1, Date date2) {
int i = compareByDay(date1, date2);
if (i < 0)
return true;
return false;
}


public static final boolean isAfterByDay(Date date1, Date date2) {
int i = compareByDay(date1, date2);
if (i > 0)
return true;
return false;
}


public static final boolean isOnSameDay(Date date1, Date date2) {
int i = compareByDay(date1, date2);
if (i == 0)
return true;
return false;
}


public static final int compareByDay(Date date1, Date date2) {
String d1 = YYYYMMDD_FORMATTER.format(date1);
String d2 = YYYYMMDD_FORMATTER.format(date2);
int retVal = 0;
try {
int dateInt1 = Integer.parseInt(d1);
int dateInt2 = Integer.parseInt(d2);
if (dateInt1 > dateInt2) {
retVal = 1;
} else if (dateInt1 < dateInt2) {
retVal = -1;
}

} catch (Exception e) {

}
return retVal;
}

public static final int compareByDateTime(Date date1, Date date2) {
long d1=date1.getTime();
long d2=date2.getTime();
int retVal = 0;
if (d1 > d2) {
retVal = 1;
} else if (d1 < d2) {
retVal = -1;
}
return retVal;
}

public static final int compareByDateTime2(Date date1, Date date2) {
long d1=date1.getTime()/1000;
long d2=date2.getTime()/1000;
int retVal = 0;
if (d1 > d2) {
retVal = 1;
} else if (d1 < d2) {
retVal = -1;
}
return retVal;
}

public static final int compareByDate(Date date1, Date date2) {
int d=calculateDays(date1,date2);
if(d>0){
return 1;
}
else if(d<0){
return -1;
}
return d;
}

public static final Date toDateWithoutMs(java.util.Date date){
return new Date((date.getTime()/1000)*1000);
}
public static final Date toDateWithoutTime(java.util.Date date){
//System.out.println("toDateWithoutTime:1"+new Date((date.getTime()/1000/60/60/24)*1000*60*60*24));
return toBizDate(toBizString(date));
}

public static final Date toGMTTimestamp(java.util.Date localDate){
TimeZone localTimeZone = SHTimeZone;
return DateUtil.toDate(localDate,localTimeZone,DateUtil.GMTTimeZone);
}


public static final Date toGMTTimestamp(java.sql.Timestamp localTimestamp){
TimeZone localTimeZone = SHTimeZone;
return DateUtil.toDate(localTimestamp,localTimeZone,DateUtil.GMTTimeZone);
}

public static final Timestamp toGMTSqlTimestamp(java.util.Date localDate){
//TimeZone localTimeZone = ((UserProfile)(MyObjects.getInstance().getObject("WAF_USERPROFILE"))).getUser().getSiteTimeZone();
return new Timestamp(toGMTTimestamp(localDate).getTime());
}


public static Timestamp toGMTSqlTimestamp(java.sql.Timestamp localTimestamp){
//TimeZone localTimeZone = ((UserProfile)(MyObjects.getInstance().getObject("WAF_USERPROFILE"))).getUser().getSiteTimeZone();
return new Timestamp(toGMTTimestamp(localTimestamp).getTime());
}


public static Timestamp getNextGMTSqlTimestamp(java.util.Date localDate){
return toGMTSqlTimestamp(getNextLocalDate(localDate));
//return toGMTTimestamp(getNextLocalDate(new Date((localDate.getTime()/(24*60*60*1000L))*(24*60*60*1000L))));
}


public static final Timestamp getPreviousGMTSqlTimestamp(java.util.Date localDate){
return toGMTSqlTimestamp(getPreviousLocalDate(localDate));
//return toGMTTimestamp(getPreviousLocalDate(new Date((localDate.getTime()/(24*60*60*1000L))*(24*60*60*1000L))));
}


public static final Date getNextGMTTimestamp(java.util.Date localDate){
return toGMTTimestamp(getNextLocalDate(localDate));
//return toGMTTimestamp(getNextLocalDate(new Date((localDate.getTime()/(24*60*60*1000L))*(24*60*60*1000L))));
}


public static final Date getPreviousGMTTimestamp(java.util.Date localDate){
return toGMTTimestamp(getPreviousLocalDate(localDate));
//return toGMTTimestamp(getNextLocalDate(new Date((localDate.getTime()/(24*60*60*1000L))*(24*60*60*1000L))));
}


public static final Date toLocalTimestamp(Timestamp gmtTimestamp){
TimeZone localTimeZone = SHTimeZone;
return DateUtil.toDate(gmtTimestamp,DateUtil.GMTTimeZone,localTimeZone);
}



public static final Date toLocalTimestamp(java.util.Date gmtDate){
TimeZone localTimeZone = SHTimeZone;
return DateUtil.toDate(gmtDate,DateUtil.GMTTimeZone,localTimeZone);
}


public static final Date getNextLocalDate(Date date) {
//TimeZone localTimeZone = ((UserProfile)(MyObjects.getInstance().getObject("WAF_USERPROFILE"))).getUser().getSiteTimeZone();
return addDays(date,1);
}


public static final Date getPreviousLocalDate(Date date) {
return addDays(date,-1);
}


public static final java.sql.Date getNextLocalSqlDate(Date date) {
return new java.sql.Date(getNextLocalDate(date).getTime());
}


public static final java.sql.Date getPreviousLocalSqlDate(Date date) {
return new java.sql.Date(getPreviousLocalDate(date).getTime());
}


public static final String toLocalString(Date date){
Locale loc=null;
loc=Locale.getDefault();
SimpleDateFormat formatter = (SimpleDateFormat)DateFormat.getDateInstance(DateFormat.MEDIUM,loc);
return formatter.format(date);

}


public static final String toLocalString(Date date,String format) {
Locale loc=Locale.getDefault();
return toLocalString(date,format,loc);
}


public static final String toLocalString(Date date,String format,Locale locale) {
String dateStr = null;
if(format==null||format.trim().length()==0){
format=DEFAULT_BIZ_DATE_FORMAT;
}
Locale loc=null;
if(locale==null){
loc=Locale.getDefault();
}
else{
loc=locale;
}
SimpleDateFormat formatter = new SimpleDateFormat(format,loc);
dateStr = formatter.format(date);
return dateStr;
}


public static final String toFullLocalString(Date date){
Locale loc=Locale.getDefault();
if(loc==null){
loc=Locale.getDefault();
}
SimpleDateFormat formatter = (SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,loc);
return formatter.format(date);

}


public static final String toFullLocalString(Date date,String format,Locale locale) {
String dateStr = null;
if(format==null||format.trim().length()==0){
format=DEFAULT_ADMIN_DATE_FORMAT;
}
Locale loc=null;
if(locale==null){
loc=Locale.getDefault();
}
else{
loc=locale;
}
SimpleDateFormat formatter = new SimpleDateFormat(format,loc);
dateStr = formatter.format(date);
return dateStr;
}


public static final Date getHostDate(){
return new Date();
}
public static final Date getNextHostDate(){
return addDays(new Date(),1);
}
public static final Date getPreviousHostDate(){
return addDays(new Date(),-1);
}


public static final java.sql.Date getHostSqlDate(){
return new java.sql.Date((new Date()).getTime());
}


public static final Date addDays(Date date,int days){
if(date==null){
return null;
}
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.DATE, days);
return cal.getTime();
}

public static final Date addWeeks(Date date,int weeks){
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.DATE, weeks*7);
return cal.getTime();
}


public static final Date addMonths(Date date,int months){
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.MONTH, months);
return cal.getTime();
}


public static final Date addQuarters(Date date,int quarters){
if(date==null){
return null;
}
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.MONTH, quarters*3);
return cal.getTime();
}


public static final Date addYears(Date date,int years){
if(date==null){
return null;
}
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.YEAR, years);
return cal.getTime();
}


public static final boolean isLeapYear(Date date){
if(date==null){
return false;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year=cal.get(Calendar.YEAR);
if (year % 4 == 0) {
if (year % 400 == 0) {
return true;
} else if (year % 100 != 0) {
return true;
}
}
return false;
}


public static final Date getFirstDayOfWeek(Date date){
if(date==null){
return null;
}
Locale locale =Locale.getDefault();
//Locale locale=Locale.CHINESE;
Calendar cal = Calendar.getInstance(locale);
cal.setTime(date);
int days=cal.get(Calendar.DAY_OF_WEEK);
return addDays(date,(-1)*days+1);
}


public static final Date getLastDayOfWeek(Date date){
if(date==null){
return null;
}
Locale locale =Locale.getDefault();
//Locale locale=Locale.CHINESE;
Calendar cal = Calendar.getInstance(locale);
cal.setTime(date);
int days=cal.get(Calendar.DAY_OF_WEEK);
return addDays(date,7-days);
}


public static final Date getFirstDayOfMonth(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DATE,1);
return cal.getTime();
}


public static final Date getLastDayOfMonth(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DATE,1);
cal.add(Calendar.MONTH,1);
cal.add(Calendar.DATE,-1);
return cal.getTime();
}

public static final Date getFirstBizDayOfMonth(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DATE,1);
return cal.getTime();
}
public static final Date getLastBizDayOfMonth(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DATE,1);
cal.add(Calendar.MONTH,1);
cal.add(Calendar.DATE,-1);
return cal.getTime();
}


public static final Date getFirstDayOfPreviousMonth(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH,-1);
cal.set(Calendar.DATE,1);
return cal.getTime();
}


public static final Date getLastDayOfPreviousMonth(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH,-1);
cal.set(Calendar.DATE,1);
return getLastDayOfMonth(cal.getTime());
}


public static final Date getFirstDayOfNextMonth(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH,1);
cal.set(Calendar.DATE,1);
return cal.getTime();
}


public static final Date getLastDayOfNextMonth(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH,1);
cal.set(Calendar.DATE,1);
return getLastDayOfMonth(cal.getTime());
}


public static final Date getFirstDayOfQuarter(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month=cal.get(Calendar.MONTH);
int quarter=month/3;

cal.set(Calendar.MONTH,quarter*3);
cal.set(Calendar.DATE,1);
return cal.getTime();
}


public static final Date getLastDayOfQuarter(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month=cal.get(Calendar.MONTH);
int quarter=month/3;

cal.set(Calendar.MONTH,quarter*3+2);
cal.set(Calendar.DATE,1);
return getLastDayOfMonth(cal.getTime());
}


public static final Date getFirstDayOfYear(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.MONTH,1);
cal.set(Calendar.DATE,1);
return cal.getTime();
}
public static final Date getFirstDayOfYear(int year){
return toBizDate(year+"01-01");
}


public static final Date getLastDayOfYear(Date date){
if(date==null){
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.MONTH,11);
cal.set(Calendar.DATE,31);
return cal.getTime();
}
public static final Date getLastDayOfYear(int year){
return toBizDate(year+"12-31");
}


public static final Date getBeginTimeOfDay(Date date){
return toBizDate(toBizString(date));
}


public static final Date getEndTimeOfDay(Date date){
return new Date(toBizDate(toBizString(addDays(date,1))).getTime()-1000);
}


public static final Date getEndTimeOfDay2(Date date){
return toBizDate(toBizString(addDays(date,1)));
}


public static final Date getGMTBeginTimeOfDay(Date date){
return getBeginTimeOfDay(toGMTTimestamp(date));
}

public static final Date getGMTEndTimeOfDay(Date date){
return getEndTimeOfDay(toGMTTimestamp(date));
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值