wjc
3 小时以前 4db3692de0001eea35f938c1224181746e72933a
app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java
@@ -4,6 +4,7 @@
import android.text.TextUtils;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.enums.Languages;
import com.hdl.photovoltaic.enums.TimeType;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.ui.home.HomePageFragment;
@@ -46,14 +47,14 @@
        switch (timeType) {
            case TimeType.day: {
                timeDateFormat = TimeUtils.zhDateYearMonthDayFormat;
                if (!UserConfigManage.getInstance().isZh()) {
                if (!UserConfigManage.getInstance().getCurrentAppLanguage().equals(Languages.zh)) {
                    timeDateFormat = TimeUtils.enDateYearMonthDayFormat;
                }
            }
            break;
            case TimeType.month: {
                timeDateFormat = TimeUtils.zhDateYearMonthFormat;
                if (!UserConfigManage.getInstance().isZh()) {
                if (!UserConfigManage.getInstance().getCurrentAppLanguage().equals(Languages.zh)) {
                    timeDateFormat = TimeUtils.enDateYearMonthFormat;
                }
            }
@@ -61,7 +62,7 @@
            case TimeType.year:
            case TimeType.all: {
                timeDateFormat = TimeUtils.zhDateYearFormat;
                if (!UserConfigManage.getInstance().isZh()) {
                if (!UserConfigManage.getInstance().getCurrentAppLanguage().equals(Languages.zh)) {
                    timeDateFormat = TimeUtils.enDateYearFormat;
                }
            }
@@ -109,13 +110,43 @@
    /**
     * 时间戳转时间(格式:yyyy-MM-dd HH:mm:ss)
     *
     * @param timestamp 时间戳
     * @param timestamp        时间戳
     * @param isDisplaySeconds 是否显示秒,true显示
     * @return -
     */
    public static String getTimeFromTimestamp(long timestamp, boolean isDisplaySeconds) {
        try {
            String pattern = "yyyy-MM-dd HH:mm:ss";
            if (isDisplaySeconds) {
                pattern = "yyyy-MM-dd HH:mm:ss";
                if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(Languages.en)) {
                    pattern = "dd-MM-yyyy HH:mm:ss";
                }
            } else {
                pattern = "yyyy-MM-dd HH:mm";
                if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(Languages.en)) {
                    pattern = "dd-MM-yyyy HH:mm";
                }
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, getLocale());
            Date date = new Date(timestamp);
            return dateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    /**
     * 时间戳转时间(格式:yyyy-MM-dd HH:mm:ss)
     *
     * @param timestamp 时间戳
     *                  ¬     * @return -
     */
    public static String getTimeFromTimestamp(long timestamp) {
        try {
            String pattern = "yyyy-MM-dd HH:mm";
            if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(LocalManageUtil.en)) {
            if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(Languages.en)) {
                pattern = "dd-MM-yyyy HH:mm";
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, getLocale());
@@ -128,6 +159,28 @@
    }
    /**
     * 时间戳转日期(格式:MM-dd)
     *
     * @param timestamp 时间戳
     *                  ¬     * @return -
     */
    public static String getDataFromTimestamp(long timestamp) {
        try {
            String pattern = "MM-dd";
            if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(Languages.en)) {
                pattern = "dd-MM";
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, getLocale());
            Date date = new Date(timestamp);
            return dateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    /**
     * 时间戳转时间(格式:yyyy-MM-dd HH:mm:ss)
     *
     * @param timestamp 时间戳