当前位置: 移动技术网 > IT编程>移动开发>Android > 仿iphone中短信以及通话记录的时间显示

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

三农在线,盖州到沈阳火车,杨殿钟简历

废话不多说,上代码
复制代码 代码如下:

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;
    }
   }
  }
 }

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网