03-23-2009 11:19 AM
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.
03-23-2009 11:57 AM - edited 03-23-2009 11:59 AM
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) ) ;
03-06-2010 05:17 PM
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
12-09-2011 04:37 AM
02-15-2013 06:11 AM
02-15-2013 06:12 AM
02-15-2013 06:13 AM
02-15-2013 06:15 AM
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.