Calculate the number of days remaining until the next anniversary. Help, please!

Hi guys,.

I'm new to the forum and to the development of BB. So please do not judge harshly if the answer to my question seems obvious.

I need to calculate the number of days until the next birthday (taking into account any valid birth date)

After looking at the API and the forum search, I realized that I could

calculate the difference between two dates in milliseconds and then divide the delta of the value of a day in milliseconds. That is to say:

birthdayCalendar.set (Calendar.YEAR, those);

Date1 = birthdayCalendar.getTime () .getTime ();

date2 = System.currentTimeMillis ();

Delta = date1 - date2

numOfDays = delta\DateTimeUtilities.ONEDAY

Here's my question. How do I create a valid date1 what about leap years?

Maybe there's a better way to solve this problem?

Any help is greatly appreciated.

I agree that the determination of the number of days between today and Feb. 29 could be a little difficult, if it is not a leap year.  I suspect that the calendar has a certain built-in mechanism to compensate for this, but your solution to choose a date is better.

DST has a role to play, and Yes, the calendar makes up for it.  Let us take two dates, for example (before DST) March 1 and June 1 (after the DST).  If you take a calendar and set the same hour, minute, etc., they are all the same except for dates, then subtract one from the other, and then divide by the number of milliseconds in 1 hour, you calculate the number of hours between the same time on two different days.  You will find that it is not a multiple of 24 hours - because there is actually an hour less than the number of days since the clocks move forward (in the northern hemisphere anyway...),

In your case, you are not calculating the number of hours, you calculate the number of days.  But you will be dividing by [24 * (time in an hour)].  If you take [23 * (time in an hour)] and divide it by [24 * (time in an hour)], using arithmetic on integers, you will end up 0.  The easiest to get around this, who also works for the end of the DST too, is to simply add one hour to the date before the division.

Hope that makes sense...

Tags: BlackBerry Developers

Similar Questions

Maybe you are looking for

  • Does not update shockwave flash

    Try to update Adobe Shockwave Flash - went to the Mozilla, download install_flashplayer11x32_mssd_aaa_aih.exe plugin page, but it keeps failing to install - get "Unable to load the configuration of the application" error. Any help appreciated, thanks

  • Java plugin is not install - JRE 1.7 u10 on Firefox 18.0.1

    I have serious problems because 18.0.1 Firefox could not install the plugin and I can access some Web sites I've used frequently.I do the installation of the plugin and it is not installed, do it manually is not installed. I don't know what to do.Eve

  • HPDM: HPDM can't see any of my thin clients

    A few months ago, I set up a server HPDM on Win 2012r2 and light HP 12, mainly mt245 clients. I could see all the thin clients with HPDM, I even used it for the Image of each of them. Yesterday, I went to add a new abd mt245 the image. All TCs went f

  • Satellite A300 - built into the camera hangs

    Salvation; I have a problem on my laptop, built-in camera. After opening, using Yahoo messenger (webcam) or by Assistant camera camera software, in a few seconds, it crashes.I tried to check if the pilot does not work, he said that there was last upd

  • Z10 BBW has stopped working

    Someone at - it else seen here Z10 BBW stop working?  At the launch, it was just the spinning activity indicator.  Never fills with information.  Restarted the unit a couple of times.  Good and cellular WiFi connections.  The navigation is very good.