简体   繁体   中英

Get Current System Time And After That Want To add 30 minutes in That Time

I want to get current time in my application.
Then i want to add 30 minutes in the current time.
can any one help me how to achieve this?

I am getting start and stop time from my web service. eg: ((start time)11:00 am to (stop time) 11:00 pm) now i want to add 30 minutes in the current time till the stop time reach.

Calendar now = Calendar.getInstance();
now.add(Calendar.MINUTE, 30);

And to output the time you could use

// 24 hours format
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
// AM/PM format
SimpleDateFormat df = new SimpleDateFormat("hh:mm aa");

System.out.println(df.format(now.getTime()));

Use the following:

//get current Time
long currentTime = System.currentTimeMillis();
//now add half an hour, 1 800 000 miliseconds = 30 minutes
long halfAnHourLater = currentTime + 1800000;
System.currentTimeMillis()+(30*60*1000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM