取得当日开始时间和结束时间

 

String dateStr = "04-17";

Calendar c1 = Calendar.getInstance();
        c1.set(Calendar.YEAR, c1.get(Calendar.YEAR));
        c1.set(Calendar.MONDAY, Integer.parseInt(dateStr.substring(0, dateStr.indexOf("-")))-1);
        c1.set(Calendar.DATE, Integer.parseInt(dateStr.substring(dateStr.indexOf("-")+1,dateStr.length())));
        c1.set(Calendar.HOUR_OF_DAY, 0);
        c1.set(Calendar.MINUTE, 0);
        c1.set(Calendar.SECOND, 0);
        Calendar c2 = Calendar.getInstance();
        c2.set(Calendar.YEAR, c2.get(Calendar.YEAR));
        c2.set(Calendar.MONDAY, Integer.parseInt(dateStr.substring(0, dateStr.indexOf("-")))-1);
        c2.set(Calendar.DATE, Integer.parseInt(dateStr.substring(dateStr.indexOf("-")+1,dateStr.length())));
        c2.set(Calendar.HOUR_OF_DAY, 23);
        c2.set(Calendar.MINUTE, 59);
        c2.set(Calendar.SECOND, 59);

posted @ 2017-04-20 14:01  baby孔祥超  阅读(243)  评论(0编辑  收藏  举报