java - Android: Incorrect Date when Converting from Seconds -
i'm parsing date data xml string hierarchy of model objects. dates in 10-digit seconds format. use method below convert seconds date objects
public static date getdatefromsecondsstring(string seconds){ try{ long millis = long.parselong(seconds) * 1000; date date = new date(millis); return date; } catch(exception ex){ ex.printstacktrace(); } return null; }
here's problem...
when step through parsing code @ run-time (the code snippet shown below), date conversion method returning expected date.
element startdateelt = eventelt.getchild("start_date"); if(startdateelt != null){ startdateelt.setendtextelementlistener(new endtextelementlistener() { @override public void end(string body) { currevent.startdate = datetimeutil.getdatefromsecondsstring(body); } }); }
however, once have finished populating model objects parsed data, dates wrong. here examples:
seconds: 1369206000, should be: 2013-05-22, unfortunately is: 2013-05-03 seconds: 1369292400, should be: 2013-05-23, unfortunately is: 2013-05-04 seconds: 1369551600, should be: 2013-05-26, unfortunately is: 2013-04-30 seconds: 1369638000, should be: 2013-05-27, unfortunately is: 2013-05-01 seconds: 1369724400, should be: 2013-05-28, unfortunately is: 2013-05-02
i have looked through code make sure nothing modifying dates between time xml parsed , time display dates. know date objects in java/android little messed up, behave this?
any suggestions or insights appreciated.
turns out, problem was using date.today() in places should have been using date.todate() instead. grrr! dislike java's date implementation.
thanks of gave 2 cents, , let warning may confusing today() todate().
Comments
Post a Comment