我需要创建两个日期对象。如果当前日期和时间是 2012 年 3 月 9 日上午 11:30,那么
- date object d1 should be 9th March 2012 12:00 AM
- date object d2 should contain the current date itself
不输入日期,是系统日期。
更新:
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.
应该是 2012 年 3 月 9 日星期五 00:00:00 IST
关于java - 在午夜时间用 Java 获取今天的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9629636/