1

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

Yuva iOS
  • 35
  • 4

1 Answers1

1

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());
Hariharan
  • 24,741
  • 6
  • 50
  • 54