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?
我想在我的申请中获得当前时间。然后我想在当前时间添加30分钟。谁能帮助我如何实现这一目标?
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.
我正在从我的网络服务开始和停止时间。例如:((开始时间)上午11:00到(停止时间)下午11:00)现在我想在当前时间加30分钟直到停止时间到达。
3 个解决方案
#1
22
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()));
#2
9
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;
#3
7
System.currentTimeMillis()+(30*60*1000);
#1
22
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()));
#2
9
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;
#3
7
System.currentTimeMillis()+(30*60*1000);