Reputation: 35
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
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