Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 216
Registered: ‎09-11-2008
My Device: 9000(Bold)

Re: Comparing dates problem

Hi,

 

Thanks for the help, i just tested the app. with the debug info and here are the results:

//when the date is 31/3/09
Now: 1241172963530, XML: 1240395363530, Diff: 777600000, Diff in Days: 9, Remainder: 0

 

//when the date is 1/4/09
Now: 1241172904140, XML: 1240395304140, Diff: 777600000, Diff in Days: 9, Remainder: 0

As you can see the Xml date is changed from some reason although it's constant, but the main issue is the difference in the now date: the difference between the 2 dates is very small. I also tested it when the date is 28/2/09 and 1/3/09 and i got the same result- small difference.

What do you think the problem is- in my app. or in BB OS?

I also tried something else:

 

long daysBetween = 0;
Date updatedDate = new Date(tmpCalendar.getTime().getTime());
while (tmpCalendar.before(nowCalender)) {  
       updatedDate.setTime(updatedDate.getTime() + DateTimeUtilities.ONEDAY);
       tmpCalendar.setTime(updatedDate);
       daysBetween++;
}

 

but i got the same exact result. no difference in # of days when the date is 31/3 or 1/4.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Comparing dates problem

[ Edited ]

Really should spend a bit more time on this rather than dipping in and out, but I have another quick suggestion:

 

myCalender.set(Calendar.MONTH, xmlMon);//04

 

If you have specified xmlMon as 4 (as this suggests) then you are actually specifying Month 5, because month 0 is January.  As a result I think in your Calendar setting you are setting April 31, which is not legal.  Not sure what it will do with that.

 

To prove this, use SimpleDateFormat to output the Calendar times.  Note that these will display local times.

 

private SimpleDateFormat sdFormat = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss.SSS" ) ; // Use this to format Dates

System.out.println("Now Time: " + sdFormat .formatLocal(nowTime) +

", XML Time: " + sdFormat .formatLocal(xmlTime) ) ; 

Message Edited by peter_strange on 03-23-2009 03:59 PM
Developer
Posts: 77
Registered: ‎11-03-2009
My Device: 9810 Torch
My Carrier: VIPnet

Re: Comparing dates problem

Hi, all!

 

I've had similar problem with returning days... and what Peter said about the months was the problem,

 

In line,

myCalender.set(Calendar.MONTH, xmlMon);//04

you are saying that 04 actually represents 5th month (May), as the starting month (January) is 0.

 

I was setting up a similar code-check, and it seemed that I need to write one-month lower value that I wanted to.  Your answer just confirmed what I thought.

 

So, yes, the problem is most likely with the months starting with zero (0).

 

may I ask why is it that the starting month is 0 and not 1?

 

BR,

Hrvoje

Developer
Posts: 134
Registered: ‎08-03-2011
My Device: torch, Z10
My Carrier: Vodafone, Airtel

Re: Comparing dates problem

Hi,

try this

Calendar systemDate = Calendar.getInstance();
systemDate.setTime(new Date());
while (tmpCalendar.before(systemDate)) {
Date workDate = tmpCalendar.getTime();
long workDateTime = workDate.getTime() + ((long)DateTimeUtilities.ONEDAY);
workDate.setTime(workDateTime);
tmpCalendar.setTime(workDate);
}

Regards
Brajesh Sanodiya
-----------------------------------------------------------------------
"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
-----------------------------------------------------------------------
New Member
Posts: 3
Registered: ‎02-15-2013
My Device: 9900
My Carrier: Software Developer

Re: Comparing dates problem

Date dateObject = new Date(HttpDateParser.parse("2013-02-10"));
Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal1.setTime(dateObject);

Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
System.out.println("Cal 1-"+cal1.getTime());

Calendar systemDate = Calendar.getInstance();
systemDate.setTime(new Date());

System.out.println("Cal date-"+systemDate.getTime());

while (cal1.before(systemDate))
{
Date workDate = cal1.getTime();
long workDateTime = workDate.getTime() + ((long)DateTimeUtilities.ONEDAY);
workDate.setTime(workDateTime);
cal1.setTime(workDate);
SimpleDateFormat postFormater = new SimpleDateFormat("yyyy-MM-dd");
String newDateStr = postFormater.format(cal1.getTime());

System.out.println("Between Dates -"+newDateStr);
}
New Member
Posts: 3
Registered: ‎02-15-2013
My Device: 9900
My Carrier: Software Developer

Re: Comparing dates problem

Mugdha Kaushik
Highlighted
New Member
Posts: 3
Registered: ‎02-15-2013
My Device: 9900
My Carrier: Software Developer

Re: Comparing dates problem

Working Demo
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Comparing dates problem

I am not sure why you posted this code, but be aware that over daylight saving time changes, a day is not

DateTimeUtilities.ONEDAY

millseconds long.