From d18731ccfee884f839235adf2d289abe4b6ccf97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=8E=89=E4=B9=85?= <1484288157@qq.com> Date: Fri, 15 May 2020 18:11:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=85=89=E7=8E=AF=E5=8A=A9?= =?UTF-8?q?=E6=89=8BV4.0.1-=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA=E8=A7=84?= =?UTF-8?q?=E5=88=99=E4=BC=98=E5=8C=96=20https://gitlab.ghzs.com/pm/halo-a?= =?UTF-8?q?pp-issues/-/issues/865?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gh/common/util/NewsUtils.java | 49 +------------------ 1 file changed, 2 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/com/gh/common/util/NewsUtils.java b/app/src/main/java/com/gh/common/util/NewsUtils.java index 02ec919dd7..77c9526d01 100644 --- a/app/src/main/java/com/gh/common/util/NewsUtils.java +++ b/app/src/main/java/com/gh/common/util/NewsUtils.java @@ -118,57 +118,12 @@ public class NewsUtils { * 设置新闻发布时间 */ public static void setNewsPublishOn(TextView textView, long time) { - time = time * 1000; - SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); - try { - long today = format.parse(format.format(new Date())).getTime(); - if (time >= today && time < today + 86400 * 1000) { - format.applyPattern("HH:mm"); - textView.setText(format.format(time)); - } else if (time >= today - 86400 * 1000 && time < today) { - format.applyPattern("HH:mm"); - textView.setText(String.format("昨天 %s", format.format(time))); - } else { - format.applyPattern("yyyy年MM月dd日 HH:mm"); - textView.setText(format.format(time)); - } - } catch (ParseException e) { - e.printStackTrace(); - format.applyPattern("yyyy年MM月dd日 HH:mm"); - textView.setText(format.format(time)); - } + CommentUtils.setCommentTime(textView, time); } public static void setNewsDetailTime(TextView textView, long time) { - SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); - try { - long today = format.parse(format.format(new Date())).getTime(); - long day = time * 1000; - if (day >= today && day < today + 86400 * 1000) { - long min = new Date().getTime() / 1000 - day / 1000; - int hour = (int) (min / (60 * 60)); - if (hour == 0) { - if (min < 60) { - textView.setText("刚刚"); - } else { - textView.setText(String.format(Locale.getDefault(), "%d分钟前", (int) (min / 60))); - } - } else { - textView.setText(String.format(Locale.getDefault(), "%d小时前", hour)); - } - } else if (day >= today - 86400 * 1000 * 100 && day < today) { - format.applyPattern("HH:mm"); - textView.setText("昨天 "); - } else { - format.applyPattern("yyyy-MM-dd"); - textView.setText(format.format(day)); - } - } catch (ParseException e) { - e.printStackTrace(); - format.applyPattern("yyyy-MM-dd"); - textView.setText(format.format(time * 1000)); - } + CommentUtils.setCommentTime(textView, time); } public static String getFormattedTime(long time) {