Adding 15 min to current time in java

Posted on 2009-05-05
Last Modified: 2012-05-06

I am working in java

I want to add 15 minutes to current time

How do we do that

Please guide

Many Thanks
Question by:tia_kamakshi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Expert Comment

ID: 24302918
Date fifteenLater = new Date(System.currentTimeMilllis() + (100*60*60*15));
LVL 86

Expert Comment

ID: 24302920
Oops - typo
Date fifteenLater = new Date(System.currentTimeMilllis() + (1000*60*60*15));

Open in new window

LVL 86

Expert Comment

ID: 24302924
... and get rid of the extra 'l' in Millis ;-)
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

LVL 92

Assisted Solution

objects earned 166 total points
ID: 24302942
you use the Calendar class to do any date arithmetic, you'll find an example here

LVL 86

Assisted Solution

CEHJ earned 166 total points
ID: 24302987
You can save the original 'now' if you need it as a reference. The following prints

Tue May 05 11:04:14 BST 2009
Tue May 05 11:19:14 BST 2009

on my system
        Date now = new Date();
        Date fifteenLater = new Date(now.getTime() + (1000L*60*15));

Open in new window


Accepted Solution

ozlevanon earned 168 total points
ID: 24303162
I believe the best way is to use Calendar class. Of course you can use Date or directly using System. See examples in the code below.
			// Using calendar calss
			GregorianCalendar now = new GregorianCalendar();
			now.add(Calendar.MINUTE, 15);
			Date fifteenMinutesAway = now.getTime();
			long fifteenMinutesAwayInMilliseconds = now.getTime().getTime();
			// Using Date or System.currentTimeMillis()
			Date date1 = new Date(System.currentTimeMillis() + 15 * 60 * 1000);
			Date date2 = new Date(new Date().getTime() + 15 * 60 * 1000);

Open in new window


Author Closing Comment

ID: 31577935
Many Thanks
LVL 86

Expert Comment

ID: 24312266

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unhandled exception type Exception 18 65
Setup GlassFish 4 55
passing enum to a method 4 49
Tomcat 9 + java 8 error while trying to deploy a war file 2 850
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question