[android-beginners] inconsistent results from DateUtils.getRelativeTimeSpanString
Hi all, I'm working on my first Android app and getting odd results while using DateUtils.getRelativeTimeSpanString(). The first time the method gets called it seems to work fine, returning a character sequence such as "27 days ago". But the next time the method gets called it always returns a character sequence that is the same as the startDate, such as "Aug 12, 2009". This seems strange. The method can be written in one line, but I split it out to four lines and put a break point on each line. I can step through line by line and everything looks correct ("year", "month", "day", "startDate" and "now" are appropriate values) until the timeSpan gets set, where it suddenly returns the startDate instead of a span of x days. Is this a bug in DateUtils.getRelativeTimeSpanString or, more likely, I am just overlooking something simple. public CharSequence myTimeSpan(int year, int month, int day) { long startDate = new GregorianCalendar(year, month, day).getTime ().getTime(); long now = new GregorianCalendar().getTime().getTime(); CharSequence timeSpan = DateUtils.getRelativeTimeSpanString (startDate, now, DateUtils.DAY_IN_MILLIS); return timeSpan; } thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: inconsistent results from DateUtils.getRelativeTimeSpanString
Anyone? On Sep 7, 5:58 pm, podoboq wrote: > Hi all, > > I'm working on my first Android app and getting odd results while > using DateUtils.getRelativeTimeSpanString(). The first time the > method gets called it seems to work fine, returning a character > sequence such as "27 days ago". But the next time the method gets > called it always returns a character sequence that is the same as the > startDate, such as "Aug 12, 2009". This seems strange. > > The method can be written in one line, but I split it out to four > lines and put a break point on each line. I can step through line by > line and everything looks correct ("year", "month", "day", "startDate" > and "now" are appropriate values) until the timeSpan gets set, where > it suddenly returns the startDate instead of a span of x days. Is > this a bug in DateUtils.getRelativeTimeSpanString or, more likely, I > am just overlooking something simple. > > public CharSequence myTimeSpan(int year, int month, int day) > { > long startDate = new GregorianCalendar(year, month, day).getTime > ().getTime(); > long now = new GregorianCalendar().getTime().getTime(); > CharSequence timeSpan = DateUtils.getRelativeTimeSpanString > (startDate, now, DateUtils.DAY_IN_MILLIS); > return timeSpan; > > } > > thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: inconsistent results from DateUtils.getRelativeTimeSpanString
Anyone? Bueller?Bueller? :) On Sep 9, 4:54 pm, podoboq wrote: > Anyone? > > On Sep 7, 5:58 pm, podoboq wrote: > > > > > Hi all, > > > I'm working on my first Android app and getting odd results while > > using DateUtils.getRelativeTimeSpanString(). The first time the > > method gets called it seems to work fine, returning a character > > sequence such as "27 days ago". But the next time the method gets > > called it always returns a character sequence that is the same as the > > startDate, such as "Aug 12, 2009". This seems strange. > > > The method can be written in one line, but I split it out to four > > lines and put a break point on each line. I can step through line by > > line and everything looks correct ("year", "month", "day", "startDate" > > and "now" are appropriate values) until the timeSpan gets set, where > > it suddenly returns the startDate instead of a span of x days. Is > > this a bug in DateUtils.getRelativeTimeSpanString or, more likely, I > > am just overlooking something simple. > > > public CharSequence myTimeSpan(int year, int month, int day) > > { > > long startDate = new GregorianCalendar(year, month, day).getTime > > ().getTime(); > > long now = new GregorianCalendar().getTime().getTime(); > > CharSequence timeSpan = DateUtils.getRelativeTimeSpanString > > (startDate, now, DateUtils.DAY_IN_MILLIS); > > return timeSpan; > > > } > > > thanks in advance.- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---