- 论坛徽章:
- 0
|
new Date() will get the current time like:
Calendar calendar = new GregorianCalendar();
return calendar.getTime();
if you want to set the hour and min to 0, you can
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
but this doesn't work(I don't know why) so I had to do like this:
java.sql.Date.valueOf(DateUtils.formatDateToDate(new Date()));
DateUtils.formatDateToDate :
public static String formatDateToDate(Date inDate) {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
return sf.format(inDate);
}
That worked well. Because in the database date type doesn't have hour and min, only
timestamp has these.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/15909/showart_351800.html |
|