在午夜时间在Java中获取今天的日期
问题描述:
我需要创建两个日期对象。如果当前日期和时间是2012年3月9日上午11:30,那么
I need to create two date objects. If the current date and time is March 9th 2012 11:30 AM then
- 日期对象d1应为 2012年3月9日12:00 AM
- 日期对象d2应包含当前日期本身
日期不会输入,系统日期。
The date will not be entered, it is system date.
更新:
Date dt = new Date();
System.out.print(dt.toString());
给出当前日期和时间
答
Calendar c = new GregorianCalendar();
c.set(Calendar.HOUR_OF_DAY, 0); //anything 0 - 23
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
Date d1 = c.getTime(); //the midnight, that's the first second of the day.
应为Fri Mar 09 00:00:00 IST 2012
should be Fri Mar 09 00:00:00 IST 2012