欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

仿iphone中短信以及通话记录的时间显示

程序员文章站 2024-02-01 23:32:28
废话不多说,上代码复制代码 代码如下:public string getrelativetimespanstringforiphone(long time,long now...
废话不多说,上代码
复制代码 代码如下:

public string getrelativetimespanstringforiphone(long time,long now){
  simpledateformat formatter = null;
  resources res = mcontext.getresources();
  formatter = new simpledateformat("yy-mm-dd");
  string yearmonthday = formatter.format(time);
  if(time>now){
   return yearmonthday;
  }
  formatter = new simpledateformat("e");
  string dayofweek = formatter.format(time);

  formatter = new simpledateformat("kk:mm");
  string hourminuoftime = formatter.format(time);

  formatter = new simpledateformat("kk:mm:ss");

  string hourminusecofnow = formatter.format(now);

  long millisecofnow = getmillisecofnow(hourminusecofnow);

  if((now-millisecofnow<time)||(now-millisecofnow==time)){
   string timeofcurrentday = hourminuoftime;
   string[] hourandminute = timeofcurrentday.split(":");
   int hour =integer.parseint(hourandminute[0]);
   contentresolver cv = mcontext.getcontentresolver();
            string strtimeformat = android.provider.settings.system.getstring(cv,android.provider.settings.system.time_12_24);
            if(strtimeformat!=null){
                if(strtimeformat.equals("12")){
                    if(hour>12){
                    return  res.getstring(r.string.pm)+hour%12+":"+hourandminute[1];
                    }else{
                        return  res.getstring(r.string.am)+hour%12+":"+hourandminute[1];
                    }
                }else{
                    return hour%24+":"+hourandminute[1];
                }
            }else{
                return hour%24+":"+hourandminute[1];
            }
  }else{   

   if(now-518400000l-millisecofnow>time){
    return yearmonthday;
   }else{
    if(now-millisecofnow-86400000l<time){
     //end:modified by sunjinbiao on 20120823 for bug[540] 
     return res.getstring(r.string.yesterday);

    }else{      
     return dayofweek;
    }
   }
  }
 }