获取当天(今日)零点零分零秒
1.日期格式的
Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Date zero = calendar.getTime();
2.时间戳
long current = System.currentTimeMillis(); long zero = current/(1000*3600*24)*(1000*3600*24) - TimeZone.getDefault().getRawOffset();
public static void main(String[] args) { long current=System.currentTimeMillis();//当前时间毫秒数 long zero=current/(1000*3600*24)*(1000*3600*24)-TimeZone.getDefault().getRawOffset();//今天零点零分零秒的毫秒数 long twelve=zero+24*60*60*1000-1;//今天23点59分59秒的毫秒数 long yesterday=System.currentTimeMillis()-24*60*60*1000;//昨天的这一时间的毫秒数 System.out.println(new Timestamp(current));//当前时间 System.out.println(new Timestamp(yesterday));//昨天这一时间点 System.out.println(new Timestamp(zero));//今天零点零分零秒 System.out.println(new Timestamp(twelve));//今天23点59分59秒 }
http://www.cnblogs.com/cc-java/p/6699045.html