11-17-2012 05:25 AM - edited 11-17-2012 05:26 AM
I have this piece of code that doesn't seem to be working, it's giving me an error 104.
Date timenow = new Date(System.currentTimeMillis());
String timenowstr = new String(timenow.toString());
int timenowint = Integer.parseInt(timenowstr);
String timeposted = new String(1343084902); // this is standard php time(); from the DB
int timepostedint = Integer.parseInt(timeposted);
int subtracttime = timepostedint - timenowint;
int getdays = subtracttime/(60*60*24*2);
String stringdate = String.valueOf(subtracttime);
If I only parse through the date from the DB, then it works, but as soon as I add the other bits, it breaks.
11-17-2012 08:38 AM
Once again, it is useful if you give us as much detail as you can, - telling us which statement is getting the error makes our job easier so we are more likely to help you.
Time on BlackBerry is usually represented using a long - milliseconds since the Unix epoch - so I would work in longs rather than ints when doing date/time manipulation.
php time() is of course seconds since the Unix Epoch, so needs to be multiplied by 1000 to make the same as BlackBerry time.
Review your code to make sure this difference has been correctly managed.
Also be aware that Daylight Saving can throw curve balls at date/time calculations when the dates involved span the time change. Not saying it effects this code, just saying it might.
11-19-2012 03:33 AM
This code makes no sense:
Date timenow = new Date(System.currentTimeMillis()); String timenowstr = new String(timenow.toString()); int timenowint = Integer.parseInt(timenowstr);
You have a long, build a date out of it, read that as a string and parse this as an int, or rather, try to
.If you check http://www.blackberry.com/developers/docs/7.1.0api
Usually it is the best to just use the long values until you want to display something on the interface.
Store the "time then" as a long as well, and subtract it.
You can use simple arithmetics like longValue/1000 for seconds, /60000 for minutes etc. Be aware of the different operators '/' and '%'
11-19-2012 04:22 AM