zoukankan      html  css  js  c++  java
  • 2. java获取下周日-下周六的时间

    String[] arrDate = new String[7];
    String[] arrWeek = new String[7];

    int mondayPlus = 0;
    Calendar cd = Calendar.getInstance();
    // 获得今天是一周的第几天,星期日是第一天,星期二是第二天......
    int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1; // 因为按中国礼拜一

    if (dayOfWeek == 1) {
      mondayPlus = 0;
    } else {
      mondayPlus = 1 - dayOfWeek;
    }

    for(int i=0; i<7; i++) {
      GregorianCalendar currentDate = new GregorianCalendar();
      currentDate.add(GregorianCalendar.DATE, mondayPlus + 6 + i);
      Date monday = currentDate.getTime();
      //DateFormat df = DateFormat.getDateInstance();
      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd EE");
      String preMonday = df.format(monday);
      String[] strArr = preMonday.split(" ");
      //存放日期
      arrDate[i] = strArr[0];
      //存放周几
      arrWeek[i] = strArr[1];
      System.out.println(arrDate[i]+","+arrWeek[i]);
    }

  • 相关阅读:
    C++中的ravalue学习笔记
    C++中的抽象类
    C++中的显式类型转换
    C++中的继承和多继承
    C++中的多态
    Yocto学习笔记
    HIDL学习笔记
    hadoop2.5搭建过程
    《Redis设计与实现》学习笔记
    40 数组中只出现一次的数字
  • 原文地址:https://www.cnblogs.com/zkx4213/p/4893072.html
Copyright © 2011-2022 走看看