zoukankan      html  css  js  c++  java
  • 时间日期类型格式化

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

  • 相关阅读:
    作业3月30号
    21、,模块与包的使用
    作业3月26号
    20、面向函数与匿名函数及模块
    作业3月25号
    19、迭代器及函数的递归调用
    作业3月24号
    06-函数
    3.17---购物车练习
    3.15---文件处理练习2
  • 原文地址:https://www.cnblogs.com/kedoudejingshen/p/4548005.html
Copyright © 2011-2022 走看看