久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      • <bdo id='Yx964'></bdo><ul id='Yx964'></ul>
      <legend id='Yx964'><style id='Yx964'><dir id='Yx964'><q id='Yx964'></q></dir></style></legend>

        <i id='Yx964'><tr id='Yx964'><dt id='Yx964'><q id='Yx964'><span id='Yx964'><b id='Yx964'><form id='Yx964'><ins id='Yx964'></ins><ul id='Yx964'></ul><sub id='Yx964'></sub></form><legend id='Yx964'></legend><bdo id='Yx964'><pre id='Yx964'><center id='Yx964'></center></pre></bdo></b><th id='Yx964'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Yx964'><tfoot id='Yx964'></tfoot><dl id='Yx964'><fieldset id='Yx964'></fieldset></dl></div>

      1. <tfoot id='Yx964'></tfoot>

        <small id='Yx964'></small><noframes id='Yx964'>

        相對時間跨度的自定義格式

        Custom format for relative time span(相對時間跨度的自定義格式)
          <bdo id='1sLns'></bdo><ul id='1sLns'></ul>
        • <tfoot id='1sLns'></tfoot>
            <legend id='1sLns'><style id='1sLns'><dir id='1sLns'><q id='1sLns'></q></dir></style></legend>

              <small id='1sLns'></small><noframes id='1sLns'>

                <tbody id='1sLns'></tbody>
                  <i id='1sLns'><tr id='1sLns'><dt id='1sLns'><q id='1sLns'><span id='1sLns'><b id='1sLns'><form id='1sLns'><ins id='1sLns'></ins><ul id='1sLns'></ul><sub id='1sLns'></sub></form><legend id='1sLns'></legend><bdo id='1sLns'><pre id='1sLns'><center id='1sLns'></center></pre></bdo></b><th id='1sLns'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1sLns'><tfoot id='1sLns'></tfoot><dl id='1sLns'><fieldset id='1sLns'></fieldset></dl></div>
                  本文介紹了相對時間跨度的自定義格式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試創建一種自定義格式來顯示經過的時間.

                  I'm trying to create an custom format to display the elapsed time.

                  現在我正在使用:

                  CharSequence relativeTimeSpan = DateUtils.getRelativeTimeSpanString(
                       dateObject.getTime(), 
                       System.currentTimeMillis(), 
                       DateUtils.SECOND_IN_MILLIS,
                       flags);
                  

                  這會返回像這樣的相對時間跨度:

                  This returns relative time spans like this:

                  • 1 分鐘前
                  • 36 分鐘前
                  • 4 小時前

                  ...

                  我想要做的是顯示這個,像這樣:

                  What I'm trying to do is display this, like this:

                  • 1m
                  • 36m
                  • 4 小時

                  ...

                  我知道 DateUtils 有 FORMAT_ABBREV_ALL 標志,但這并沒有像我想要的那樣縮寫字符串......

                  I know DateUtils has FORMAT_ABBREV_ALL flag, but this doesn't abbreviate the string like I want to...

                  我怎樣才能為此創建一些自定義的東西?

                  How can I create something custom for this ?

                  推薦答案

                  我已經在我的 twitter 模塊中完成了這個

                  i have done this in my twitter module

                  public static String getTimeString(Date fromdate) {
                  
                      long then;
                      then = fromdate.getTime();
                      Date date = new Date(then);
                  
                      StringBuffer dateStr = new StringBuffer();
                  
                      Calendar calendar = Calendar.getInstance();
                      calendar.setTime(date);
                      Calendar now = Calendar.getInstance();
                  
                      int days = daysBetween(calendar.getTime(), now.getTime());
                      int minutes = hoursBetween(calendar.getTime(), now.getTime());
                      int hours = minutes / 60;
                      if (days == 0) {
                  
                          int second = minuteBetween(calendar.getTime(), now.getTime());
                          if (minutes > 60) {
                  
                              if (hours >= 1 && hours <= 24) {
                                  dateStr.append(hours).append("h");
                              }
                  
                          } else {
                  
                              if (second <= 10) {
                                  dateStr.append("Now");
                              } else if (second > 10 && second <= 30) {
                                  dateStr.append("few seconds ago");
                              } else if (second > 30 && second <= 60) {
                                  dateStr.append(second).append("s");
                              } else if (second >= 60 && minutes <= 60) {
                                  dateStr.append(minutes).append("m");
                              }
                          }
                      } else
                  
                      if (hours > 24 && days <= 7) {
                          dateStr.append(days).append("d");
                      } else {
                          dateStr.append(twtimeformat.format(date));
                      }
                  
                      return dateStr.toString();
                  }
                  
                  public static int minuteBetween(Date d1, Date d2) {
                      return (int) ((d2.getTime() - d1.getTime()) / DateUtils.SECOND_IN_MILLIS);
                  }
                  
                  public static int hoursBetween(Date d1, Date d2) {
                      return (int) ((d2.getTime() - d1.getTime()) / DateUtils.MINUTE_IN_MILLIS);
                  }
                  
                  public static int daysBetween(Date d1, Date d2) {
                      return (int) ((d2.getTime() - d1.getTime()) / DateUtils.DAY_IN_MILLIS);
                  }
                  

                  這篇關于相對時間跨度的自定義格式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網絡提供商)
                  Get current location during app launch(在應用啟動期間獲取當前位置)
                  locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)
                      <tbody id='Ocypb'></tbody>

                    <small id='Ocypb'></small><noframes id='Ocypb'>

                  1. <legend id='Ocypb'><style id='Ocypb'><dir id='Ocypb'><q id='Ocypb'></q></dir></style></legend>

                    <tfoot id='Ocypb'></tfoot>

                    • <i id='Ocypb'><tr id='Ocypb'><dt id='Ocypb'><q id='Ocypb'><span id='Ocypb'><b id='Ocypb'><form id='Ocypb'><ins id='Ocypb'></ins><ul id='Ocypb'></ul><sub id='Ocypb'></sub></form><legend id='Ocypb'></legend><bdo id='Ocypb'><pre id='Ocypb'><center id='Ocypb'></center></pre></bdo></b><th id='Ocypb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Ocypb'><tfoot id='Ocypb'></tfoot><dl id='Ocypb'><fieldset id='Ocypb'></fieldset></dl></div>

                            <bdo id='Ocypb'></bdo><ul id='Ocypb'></ul>

                          • 主站蜘蛛池模板: 午夜影院网站 | 国产精品毛片无码 | 奇米超碰在线 | 丝袜一区二区三区 | 欧美成年人网站 | 99精品99| 亚洲国产精品一区二区久久 | 国产一二三区精品视频 | 国产成人精品久久二区二区 | www.久久国产精品 | 国产欧美在线观看 | 日本在线看片 | 国产精品久久久久久久7电影 | 五月天婷婷狠狠 | 亚洲欧美一区二区三区1000 | 成人国产精品免费观看 | 亚洲国产精品一区二区三区 | 国产精品99久久久久久宅男 | 日韩欧美一级 | 国产高清精品一区二区三区 | 精品三级在线观看 | 欧美日韩在线一区二区三区 | 一区二区国产精品 | 国产精品v | 日韩手机在线看片 | 亚洲国产成人av好男人在线观看 | 欧美成视频 | 午夜精品久久久久久久久久久久久 | 久久偷人 | 日本久久久久久 | 91私密视频 | 中文在线观看视频 | cao在线| 亚洲午夜精品一区二区三区他趣 | 午夜精品久久久久久久久久久久 | av免费电影在线 | 男女羞羞免费网站 | www日本在线 | 久久天天躁狠狠躁夜夜躁2014 | 99亚洲| 亚洲精品一区av在线播放 |