Yuva iOS
Yuva iOS

Reputation: 35

Add a value to time

How to get system date and time.After getting time add 4hour to that time.Time Format is 12 Hour.I tried Like this

enter code here
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat dataFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");
    String strTime = dataFormat.format(calendar.getTime());
    calendar.add(Calendar.HOUR_OF_DAY, 4);

Example:I given 10.30AM add 4hour.I need 2.30PM

Upvotes: 1

Views: 50

Answers (1)

Hariharan
Hariharan

Reputation: 24853

Try this..

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR_OF_DAY, 4);
SimpleDateFormat dataFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
String strTime = dataFormat.format(calendar.getTime());

Upvotes: 1

Related Questions