Copied from the Sun forum (I thought this was a good post on the topic that I found awhile back)
For manipulating time dates use the Calendar class. This has an 'add' and a roll method that will calculate the correct roll over values, should the time roll over to the next day etc. It also does clever things like sort out leap years etc.
so to subtract your 12hr, 30 mins:
Date myDate = new Date(); // This is the date from which you wish to subtract.
Calendar cal = Calendar.getInstance(); cal.setTime(myDate);
// Note you 'add' a negative number. i.e. subtract cal.add(Calendar.HOUR_OF_DAY, -12 ); cal.add(Calendar.MINUTE, -30 );
Date newTime = cal.getTime(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SS"); System.out.println("new time=" + sdf.format(newTime));
The Date class is the holder of the absolute time, the Calendar is the manipulator of those times and the SimpleDateFormat will format your Date class into an acceptable output format.