Solved

Calendar increment by certain milliseconds

Posted on 2009-03-30
4
363 Views
Last Modified: 2013-11-24
Not sure what I am doing wrong in following snippet.

I am trying to do to set the time info on the Calendar object from endTime variable. Only time info (hour, minutes and seconds).  And the data will stay as is. (date, month, year).

Until this point it is fine, I get the desired result. but then I need to increment the calendar for certain milliseconds also. So I do it using last line. but that makes the calendar with some year 1939.

Calendar endTime // equivalent to 8:30am Jan 1, 1900

int StCl = 10;   // equal to 10 minutes
 

Calendar maxTime = Calendar.getInstance();

Calendar maxTimeFullInfo = (Calendar)maxTime.clone();

maxTimeFullInfo.set(Calendar.HOUR, endTime.get(Calendar.HOUR));

maxTimeFullInfo.set(Calendar.MINUTE, endTime.get(Calendar.MINUTE));

maxTimeFullInfo.set(Calendar.SECOND, endTime.get(Calendar.SECOND));

maxTimeFullInfo.set(Calendar.MILLISECOND, 0);

maxTimeFullInfo.set(Calendar.AM_PM, endTime.get(Calendar.AM_PM));

maxTimeFullInfo.setTimeInMillis(maxTimeFullInfo.getTimeInMillis() +stCl*60000);

Open in new window

0
Comment
Question by:fix2009
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24025719
use the add() method to add time to it

0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 24025724
0
 
LVL 2

Accepted Solution

by:
mhaq_java earned 300 total points
ID: 24025943
Well I doesn't see any problem in your code it works fine
but still you can use add method like this


     Calendar cal=(Calendar)endTime.clone();
     cal.add(Calendar.MILLISECOND,(10*60000));
0
 

Author Comment

by:fix2009
ID: 24065770
Yeah u r right mhaq! The code worked as is. I am not sure how it was coming up as 1939 that day. I think I didnt make any changes.

BTW -  add method is (int, int)  I cannot add a long in milliseconds.  
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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 …

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now