import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* 获取今天的凌晨时间
*/
public class 获取时间 {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.add(cal.DATE,0);
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
Date beginOfDate = cal.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println ("===:"+formatter.format(beginOfDate) );
}
}
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* 获取明天的凌晨时间
*/
public class 获取时间 {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.add(cal.DATE,1);
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
Date beginOfDate = cal.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println ("===:"+formatter.format(beginOfDate) );
}
}
|