Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add 1 hour to current time in android [duplicate]

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.

like image 756
Brinda K Avatar asked Dec 13 '12 06:12

Brinda K


1 Answers

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());
like image 200
ρяσѕρєя K Avatar answered Oct 19 '22 13:10

ρяσѕρєя K