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

时间:2021-07-23 02:34:28 

废话不多说,上代码


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;
    }
   }
  }
 }
标签:短信,通话记录,时间显示
0
投稿

猜你喜欢

  • MybatisPlus代码生成器含XML文件详解

    2023-10-25 21:51:26
  • java基础--JDK SPI概述

    2021-09-19 11:50:16
  • Android拍照或从图库选择图片并裁剪

    2023-07-01 08:21:45
  • Java实现简单无界面五子棋

    2022-07-10 12:06:02
  • Android SlidingMenu使用和示例详解

    2023-10-28 08:06:59
  • mybatis报错元素内容必须由格式正确的字符数据或标记组成异常的解决办法

    2023-01-10 15:46:37
  • 微信小程序 navigator 跳转url传递参数

    2022-03-17 05:46:56
  • 详解C# 结构体

    2023-09-30 15:37:19
  • 使用Java程序模拟实现新冠病毒传染效果

    2022-09-12 20:26:14
  • java 中动态代理机制的实例讲解

    2023-01-15 18:22:13
  • Spring中@Validated和@Valid区别浅析

    2021-10-04 23:27:22
  • Java编程实现五子棋人人对战代码示例

    2021-12-27 12:58:51
  • SpringBoot动态修改日志级别的操作

    2022-10-31 05:00:30
  • android实现密码框右侧显示小眼睛

    2023-01-26 19:54:59
  • Android基于Fresco实现圆角和圆形图片

    2023-02-14 20:03:29
  • C#中实现一次执行多条带GO的sql语句实例

    2023-07-12 10:23:53
  • Android通知栏微技巧一些需要注意的小细节

    2021-10-07 12:40:59
  • 读取Java文件到byte数组的三种方法(总结)

    2023-08-01 17:19:39
  • java 可变参数详解及实例

    2021-06-01 10:02:42
  • java selenium Selenium IDE介绍及用法

    2023-11-21 06:41:22
  • asp之家 软件编程 m.aspxhome.com