JAVA日期操作

/**
* 获取当月最大天数
* 2010-9-20上午04:51:50
* hepeng
*/
public static int getCurrentMonthMaxDay(){
Calendar a=Calendar.getInstance();
a.set(Calendar.DATE, 1);
a.roll(Calendar.DATE, -1);
return a.get(Calendar.DATE);
}

/**
* 获取今天是当月的第几天
* 2010-9-20上午04:53:10
* hepeng
*/
public static int getCurrentDay(){
Calendar c=Calendar.getInstance();
return c.get(Calendar.DAY_OF_MONTH);
}


/**
* 返回當前時間和結算開始時間的天數
* 2010-9-20上午04:53:10
* hepeng
* @throws Exception
*/
public static long getDateDays(Date d1,Date d2) throws Exception{

long dTime1 = (d1.getTime()/1000);
long dTime2 = (d2.getTime() / 1000);
long days = (dTime1 - dTime2) / (1 * 60 * 60 * 24);
return days;

}
/**
* 返回當月第一天的日期
* 2010-9-20上午04:53:10
* hepeng
* @throws Exception
*/
public static Date MonthBDate() throws Exception{
Calendar a=Calendar.getInstance();
a.set(GregorianCalendar.DAY_OF_MONTH, 1);
return a.getTime();
}

/**
* 返回當月最後一天的日期
* 2010-9-20上午04:53:10
* hepeng
* @throws Exception
*/
public static Date MonthEDate() throws Exception{
Calendar a=Calendar.getInstance();
a.set(Calendar.DATE, 1);
a.roll(Calendar.DATE, -1);
return a.getTime();
}

/**
* 获取当前月份
* 2010-9-20上午04:53:10
* hepeng
* @throws Exception
*/
public static int Month() throws Exception{
Calendar c=Calendar.getInstance();
return c.get(Calendar.MONTH)+1;
}

/**
* 将yyyyMMddHHmmss的格式转化为yyyy-MM-dd HH:mm:ss
* 2010-9-20上午04:53:10
* hepeng
* @throws Exception
*/
public static Date castTimeFormat(String date) throws Exception{
Date d = Dates.parseDate(date, "yyyyMMddHHmmss");
date = Dates.formatDate(d, "yyyy-MM-dd HH:mm:ss");
return Dates.parseDate(date);

}

/**
* 返回毫秒
* @param date 日期
* @return 返回毫秒
*/
public static long getMillis(java.util.Date date) {
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTime(date);
return c.getTimeInMillis();
}

/**
* 返回日期加上多少天后的日期
* 2010-9-23上午02:25:34
* hepeng
*/
public static Date MonthAfter(Date d,long days){
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTimeInMillis(getMillis(d) + ((long) days) * 24 * 3600 * 1000);
return c.getTime();
}

/**2010-10-13下午01:54:28
* hepeng
*/
public static int Year() {
Calendar c=Calendar.getInstance();
return c.get(Calendar.YEAR);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值