?
Solved

Calendar increment by certain milliseconds

Posted on 2009-03-30
4
Medium Priority
?
379 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
[X]
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
  • 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 200 total points
ID: 24025724
0
 
LVL 2

Accepted Solution

by:
mhaq_java earned 600 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 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