美文网首页
java 基础知识点

java 基础知识点

作者: 康熙十八年 | 来源:发表于2017-07-11 12:49 被阅读17次
  • 获取字符串格式的日期(当天、上周一、上周天,上月初,上月末,任意日期)
private void getDataStr(int type) {
        Calendar calendar = Calendar.getInstance();
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//        ParsePosition pos = new ParsePosition(0);
//        Date strtodate = formatter.parse("2017-03-01", pos);//设置任意时期进行测试
//        calendar.setTime(strtodate);
        Date start = calendar.getTime();
        Date end = calendar.getTime();
        switch (type) {
            case 0:
                //默认当天 不做处理
                break;
            case 1:
                //上周
                calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                calendar.add(Calendar.DATE, -1);
                end = calendar.getTime();
                calendar.add(Calendar.DATE, -6);
                start = calendar.getTime();
                break;
            case 2:
                //上月
                calendar.add(Calendar.MONTH, -1);
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                start = calendar.getTime();
                calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
                end = calendar.getTime();
                break;
        }
        reportDateStart = new SimpleDateFormat("yyyy-MM-dd").format(start);
        reportDateEnd = new SimpleDateFormat("yyyy-MM-dd").format(end);
        DebugUtils.error("reportDateStart : " + reportDateStart + "  ,reportDateEnd : " + reportDateEnd);
    }

相关文章

网友评论

      本文标题:java 基础知识点

      本文链接:https://www.haomeiwen.com/subject/rlzphxtx.html