Possible Duplicate:
How to increment time by 1 hour
I am using this code to get the current date and time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd:HH:mm");
String currentDateandTime = sdf.format(new Date());
System.out.println("current time date" + currentDateandTime);
Now I want to add 1 hour to this. I searched but I'm not getting the answer I want. Now I'm getting like this:
current time date2012:12:13:12:05
I want an answer like 2012:12:13:13:05
in 24hr format.
try as:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd:HH:mm");
String currentDateandTime = sdf.format(new Date());
Date date = sdf.parse(currentDateandTime);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR, 1);
System.out.println("Time here "+calendar.getTime());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With