From a3798b01c03911efcd7f7b28f78cebc35871c528 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期二, 06 八月 2024 18:37:07 +0800
Subject: [PATCH] 2024年08月06日18:37:05
---
app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java | 64 ++++++++++++++++++++++++++++----
1 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java b/app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java
index 3d5578d..fee374f 100644
--- a/app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java
+++ b/app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java
@@ -24,8 +24,52 @@
public static final String zhDateYearFormat = "yyyy";
public static final String enDateYearMonthDayFormat = "dd/MM/yyyy";
- public static final String enDateYearMonthFormat = "/MM/yyyy";
+ public static final String enDateYearMonthFormat = "MM/yyyy";
public static final String enDateYearFormat = "yyyy";
+
+ /**
+ * 鑾峰彇褰撳墠绯荤粺鏃ユ湡鏃堕棿鎴�
+ *
+ * @return 鏃堕棿鎴�
+ */
+ public static long getCurrentTimestamp() {
+ return new Date().getTime();
+ }
+
+ /**
+ * 鑾峰彇鏃ユ湡鏍煎紡 (2024/2/09,yyyy/DD/dd)
+ *
+ * @return 鏃ユ湡鏍煎紡 (2024/2/09,yyyy/DD/dd)
+ */
+ public static String getTimeDateFormat(String timeType) {
+ String timeDateFormat = TimeUtils.zhDateYearMonthDayFormat;
+ switch (timeType) {
+ case TimeType.day: {
+ timeDateFormat = TimeUtils.zhDateYearMonthDayFormat;
+ if (!UserConfigManage.getInstance().isZh()) {
+ timeDateFormat = TimeUtils.enDateYearMonthDayFormat;
+ }
+ }
+ break;
+ case TimeType.month: {
+ timeDateFormat = TimeUtils.zhDateYearMonthFormat;
+ if (!UserConfigManage.getInstance().isZh()) {
+ timeDateFormat = TimeUtils.enDateYearMonthFormat;
+ }
+ }
+ break;
+ case TimeType.year:
+ case TimeType.all: {
+ timeDateFormat = TimeUtils.zhDateYearFormat;
+ if (!UserConfigManage.getInstance().isZh()) {
+ timeDateFormat = TimeUtils.enDateYearFormat;
+ }
+ }
+ break;
+
+ }
+ return timeDateFormat;
+ }
/**
* 鑾峰彇鍒嗛挓
@@ -35,7 +79,7 @@
*/
public static String getMinuteTime(long timestamp) {
try {
- SimpleDateFormat dateFormat = new SimpleDateFormat("mm", Locale.ENGLISH);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("mm", getLocale());
Date date = new Date(timestamp);
return dateFormat.format(date);
} catch (Exception e) {
@@ -53,7 +97,7 @@
*/
public static String getDateTimestamp(long timestamp, String date_format) {
try {
- SimpleDateFormat dateFormat = new SimpleDateFormat(date_format, Locale.ENGLISH);
+ SimpleDateFormat dateFormat = new SimpleDateFormat(date_format, getLocale());
Date date = new Date(timestamp);
return dateFormat.format(date);
} catch (Exception e) {
@@ -74,7 +118,7 @@
if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(LocalManageUtil.en)) {
pattern = "dd-MM-yyyy HH:mm";
}
- SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.ENGLISH);
+ SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, getLocale());
Date date = new Date(timestamp);
return dateFormat.format(date);
} catch (Exception e) {
@@ -184,7 +228,7 @@
* @return Calendar瀵硅薄
*/
public static Calendar stringToCalendar(String dateString, String dateFormat) {
- SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
+ SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, getLocale());
Calendar calendar = Calendar.getInstance();
try {
Date date = sdf.parse(dateString);
@@ -203,7 +247,7 @@
* @return Calendar瀵硅薄
*/
public static String calendarToString(Calendar calendar, String dateFormat) {
- SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
+ SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, getLocale());
return sdf.format(calendar.getTime());
}
@@ -214,7 +258,7 @@
* @return Calendar瀵硅薄
*/
public static String dateToString(Date date, String dateFormat) {
- SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
+ SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, getLocale());
return sdf.format(date.getTime());
}
@@ -227,7 +271,7 @@
*/
public static long stringDateToTimestamp(String dateString, String dateFormat) {
try {
- SimpleDateFormat slf = new SimpleDateFormat(dateFormat, Locale.getDefault());
+ SimpleDateFormat slf = new SimpleDateFormat(dateFormat, getLocale());
Date date = slf.parse(dateString);
if (date == null) {
return 0;
@@ -238,4 +282,8 @@
return 0;
}
+ private static Locale getLocale() {
+ return Locale.ENGLISH;
+ }
+
}
--
Gitblit v1.8.0