zoukankan      html  css  js  c++  java
  • java 每个月的第一天和最后一天


    private static List<List<String>> get12MonthDate(String year){
    String dateStr = "";
    if(year!=null&&!year.equals("")){
    dateStr = year+"-01-01";
    }else{
    dateStr=new DateTime(System.currentTimeMillis()).toString("yyyy")+"-01-01";
    }
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(new DateTime(dateStr).getMillis());
    List<List<String>> result = Lists.newArrayList();
    for(int i=0;i<12;i++){
    result.add(getFirstAndLastDate(c.getTimeInMillis()));
    c.add(Calendar.MONTH, 1);
    }
    return result;
    }

    /**
    * 获取给定时间的每月的第一天和最后一天
    * @param date
    * @return
    */
    private static List<String> getFirstAndLastDate(Long date){
    List<String> list = Lists.newArrayList();
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date);
    c.add(Calendar.MONTH,0);
    c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
    list.add(new DateTime(c.getTimeInMillis()).toString("yyyy-MM-dd"));
    c.set(Calendar.DAY_OF_MONTH,c.getActualMaximum(Calendar.DAY_OF_MONTH));//当前日期既为本月最后一天
    list.add(new DateTime(c.getTimeInMillis()).toString("yyyy-MM-dd")+" 23:59:59");
    return list;
    }

  • 相关阅读:
    进制
    流程控制
    运算符
    格式化输出
    数据结构-树的遍历
    A1004 Counting Leaves (30分)
    A1106 Lowest Price in Supply Chain (25分)
    A1094 The Largest Generation (25分)
    A1090 Highest Price in Supply Chain (25分)
    A1079 Total Sales of Supply Chain (25分)
  • 原文地址:https://www.cnblogs.com/chchao/p/4160297.html
Copyright © 2011-2022 走看看