Removing time (hh:mm:ss) from Date object
hi ppl
i'm trying to make a method to remove the hours, minutes, seconds information from a Date object.
the method should produce the following result:
Mon Jul 23 10:14:33 BST 2007
TO
Mon Jul 23 00:00:00 BST 2007
i've come up with the following that resolves the problem but, is this a good solution?
publicstaticvoid main(String[] args)throws Exception{
Date old1 =new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(old1);
cal.add(Calendar.HOUR_OF_DAY, -cal.get(Calendar.HOUR_OF_DAY));
cal.add(Calendar.MINUTE, -cal.get(Calendar.MINUTE));
cal.add(Calendar.SECOND, -cal.get(Calendar.SECOND));
Date new1 = cal.getTime();
System.out.println("Old: " + old1);
System.out.println("New: " + new1);
}
thanks a lot
regards
andre

