Add 30 minutes to current time in Java

I want to get current time in my application.

Then I want to add 30 minutes to the current time.

What is the best practice to achieve this?

I can start and stop time from my web service. For example: ((start time) from 11:00 to (stop time) 11:00 pm) Now I would like to add 30 minutes to the current time until the stop time is reached.

+8
source share
3 answers
 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())); 
+23
source

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; 
+12
source
 System.currentTimeMillis()+(30*60*1000); 
+10
source

Source: https://habr.com/ru/post/1402402/


All Articles