zoukankan      html  css  js  c++  java
  • java计算今天起后7天时间 +昨天八点+今天前7天的日期

    /**
    * 今天起 近7天日期 后七天
    * @param days=6
    * @return
    */
    public static List<String> getDaysBetwwen(int days){ //最近几天日期
    List<String> dayss = new ArrayList<>();
    Calendar start = Calendar.getInstance();
    start.setTime(new Date());
    Long startTIme = start.getTimeInMillis();
    Calendar end = Calendar.getInstance();
    end.setTime(getDateAdd(days));
    Long endTime = end.getTimeInMillis();
    Long oneDay = 1000 * 60 * 60 * 24l;
    Long time = startTIme;
    while (time <= endTime) {
    Date d = new Date(time);
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    System.out.println(df.format(d));
    dayss.add(df.format(d));
    time += oneDay;
    }
    return dayss;
    }
    private static  Date getDateAdd(int days){
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_MONTH, +days);
    }




    /**
    * 昨天八点
    * @return
    */
    public static String getYesterday(){
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//日期格式
    Calendar cale = Calendar.getInstance(); // 取当前日期。
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY,8);
    calendar.set(Calendar.MINUTE,0);
    calendar.set(Calendar.SECOND,0);
    calendar.set(Calendar.MILLISECOND,0);
    calendar.add(Calendar.DAY_OF_YEAR,-1);
    Date date = calendar.getTime();
    return format.format(date);
    }


    /**
    * 今天起 近7天日期 后7天
    * @param days
    * @return
    */
    public static List<String> getDaysBetwwen(int days){ //最近几天日期
    List<String> dayss = new ArrayList<>();
    Calendar start = Calendar.getInstance();
    start.setTime(getDateAdd(days));
    Long startTIme = start.getTimeInMillis();
    Calendar end = Calendar.getInstance();
    end.setTime(new Date());
    Long endTime = end.getTimeInMillis();
    Long oneDay = 1000 * 60 * 60 * 24l;
    Long time = startTIme;
    while (time <= endTime) {
    Date d = new Date(time);
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    System.out.println(df.format(d));
    dayss.add(df.format(d));
    time += oneDay;
    }
    return dayss;
    }
    private static  Date getDateAdd(int days){
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_MONTH, -days);
    return c.getTime();
    }
  • 相关阅读:
    两种无限递归菜单
    python导出项目所有依赖库,在新环境中安装所有依赖库
    python3.6中安装Crypto模块
    在Django中settings文件内,配置MySQL和Redis
    Django继承AbstractUser新建User Model时出现fields.E304错误
    django_orm操作MySQL数据库,批量插入数据
    在用脚手架搭建vue项目时,运行vue报错
    django命令行运行失败
    redis pipline 操作
    tcpdump 与 MySQL sniffer 【转】
  • 原文地址:https://www.cnblogs.com/liuyuanchen/p/14191793.html
Copyright © 2011-2022 走看看