时间日期类型格式化

// 当天
public static DateTime getThisDay() {
DateTime now = new DateTime();
return now;
}

// 上一天
public static DateTime getPrevDay(int year, int month , int day) {
DateTime now = new DateTime();
now = now.withYear(year);
now = now.withMonthOfYear(month);
now = now.withDayOfMonth(day);
now = now.plusDays(-1);
return now;
}

// 上二天
public static DateTime getPrevDay2(int year, int month , int day) {
DateTime now = new DateTime();
now = now.withYear(year);
now = now.withMonthOfYear(month);
now = now.withDayOfMonth(day);
now = now.plusDays(-1);
return now;
}

// 下一天
public static DateTime getNextDay(int year, int month , int day) {
DateTime now = new DateTime();
now = now.withYear(year);
now = now.withMonthOfYear(month);
now = now.withDayOfMonth(day);
now = now.plusDays(1);
return now;
}

// 本月
public static DateTime getThisMonth() {
DateTime now = new DateTime();
now = now.withTime(0, 0, 0, 0);
now = now.withDayOfMonth(1);
return now;
}

// 上一个月
public static DateTime getPrevMonth(int year, int month) {
DateTime now = new DateTime();
now = now.withYear(year);
now = now.withMonthOfYear(month);
now = now.plusMonths(-1);
now = now.withTime(0, 0, 0, 0);
now = now.withDayOfMonth(1);
return now;
}

// 下一个月
public static DateTime getNextMonth(int year, int month) {
DateTime now = new DateTime();
now = now.withYear(year);
now = now.withMonthOfYear(month);
now = now.plusMonths(1);
now = now.withTime(0, 0, 0, 0);
now = now.withDayOfMonth(1);
return now;
}

// 本年
public static DateTime getThisYear() {
DateTime now = new DateTime();;
return now;
}

// 上一年
public static DateTime getPrevYear(int year) {
DateTime now = new DateTime();
now = now.withYear(year);
now = now.plusYears(-1);
return now;
}

// 下一年
public static DateTime getNextYear(int year) {
DateTime now = new DateTime();
now = now.withYear(year);
now = now.plusYears(1);
return now;
}

//上周
public static DateTime getPrevWeek(int year,int month,int week){
DateTime now = new DateTime();
now = now.withYear(year);
now = now.withMonthOfYear(month);
now = now.withWeekOfWeekyear(week);
now = now.plusWeeks(-1);
now = now.withTime(0, 0, 0, 0);
// now = now.withDayOfWeek(-1);
return now;
}
//本周
public static DateTime getThisWeek(){

DateTime now = new DateTime();
now = now.withTime(0, 0, 0, 0);
now = now.withDayOfWeek(1);
return now;

}

//下周
public static DateTime getNextWeek(int year,int month,int week){
DateTime now = new DateTime();
now = now.withYear(year);
now = now.withMonthOfYear(month);
now = now.withWeekOfWeekyear(week);
now = now.plusWeeks(1);
now = now.withTime(0, 0, 0, 0);
now = now.withDayOfWeek(1);
return now;
}

转载于:https://www.cnblogs.com/kedoudejingshen/p/4548005.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值