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;
    }

  • 相关阅读:
    JAVA --解压缩
    自动事务和手动事务的实验
    Transaction not successfully started&&Could not commit Hibernate transaction;
    POI解决大EXCLE导入崩溃的问题,3MB 7W数据 从入库到查询30s
    使用<c:foreach>同时遍历两个list
    关于Eclipse Tomcat开发中的热部署
    java的单例
    map在JSP页面取值的问题
    JSP问题
    Mybatis控制台打印sql正确,程序执行错误
  • 原文地址:https://www.cnblogs.com/kedoudejingshen/p/4548005.html
Copyright © 2011-2022 走看看