求当天的0点和23点59分59秒 这两个时刻。打印输出。

解决方案 »

  1.   


    Calendar.getInstance().get(Calendar.HOUR_OF_DAY)//小时
    Calendar.getInstance().get(Calendar.MINUTE)//分钟
    Calendar.getInstance().get(Calendar.SECOND)//秒判断即可
      

  2.   

    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    date.setHours(23);
    date.setMinutes(59);
    date.setSeconds(59);
    System.out.println(sdf.format(date));
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    System.out.println(sdf.format(date));
      

  3.   

    这些api在jdk1.6下都是过时的,有没有其它方法
      

  4.   


    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    date0 = calendar.getTime();//0点calendar.add(Calendar.DAY_OF_MONTH, 1);
    calendar.add(Calendar.MINUTE, -1);
    date1 = calendar.getTime();//23点59分59秒