• 时间日期类型格式化


    // 当天
    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;
    }

  • 相关阅读:
    JS: 子项可以来回交换的两个下拉列表
    DOM事件
    DOM基础2——元素
    DOM基础1
    JS: 随机点名程序与万年历
    G_S男女匹配算法(算法的第一个程序2016.09.19)
    Java IO流详尽解析(大神之作)
    细讲解JAVA中的IO流
    c++运算符的优先级(收好不谢)
    java程序——输出当月日历表
  • 原文地址:https://www.cnblogs.com/kedoudejingshen/p/4548005.html
Copyright © 2020-2023  润新知