android - Change DateFormat depending on Days passsed -


essentially have string contains files last modified date. i'm using:

date lastmoddate = new date(file.lastmodified()); simpledateformat formatter = new simpledateformat("k:mm a"); string formatteddatestring = formatter.format(lastmoddate); 

the end result 6:12 am. want each time period of time passed, dateformat must change. e.g.

after 1 day has gone by, last modified date = ("format1");

after week has gone by, last modified date = ("format2");

after 2 weeks have gone by, last modified date = ("format3");

does make sense? if please able show me how it's done. example native messaging app. when message created, show it's time after days gone format changes date created month etc...

i'm trying that.

calculate difference in time between last modified date , now:

 long duration = lastmoddate.gettimeinmillis() - current.gettimeinmillis();  long sec = timeunit.milliseconds.toseconds(duration);  boolean infuture = sec > 0;  // use positive value  if(!infuture)       sec = -sec;  long minutes = sec / 60  % 60;  long hours = sec / 3600 % 24;  long days = sec / 86400;   if(days > 1 && days < 7)       // use format 1  else if(days >= 7 && days < 14)       // use format 2  else       // use format 3 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -