| | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 获取分钟 |
| | |
| | | */ |
| | | 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) { |
| | |
| | | */ |
| | | 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) { |
| | | e.printStackTrace(); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | | * 时间戳转时间(格式:yyyy-MM-dd HH:mm:ss) |
| | | * |
| | | * @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(LocalManageUtil.en)) { |
| | | pattern = "dd-MM-yyyy HH:mm:ss"; |
| | | } |
| | | } else { |
| | | pattern = "yyyy-MM-dd HH:mm"; |
| | | if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(LocalManageUtil.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) { |
| | |
| | | * 时间戳转时间(格式:yyyy-MM-dd HH:mm:ss) |
| | | * |
| | | * @param timestamp 时间戳 |
| | | * @return - |
| | | * ¬ * @return - |
| | | */ |
| | | public static String getTimeFromTimestamp(long timestamp) { |
| | | try { |
| | |
| | | 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) { |
| | |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 时间戳转时间(格式:yyyy-MM-dd HH:mm:ss) |
| | |
| | | * @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); |
| | |
| | | * @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()); |
| | | } |
| | | |
| | |
| | | * @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()); |
| | | } |
| | | |
| | |
| | | */ |
| | | 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; |
| | |
| | | return 0; |
| | | } |
| | | |
| | | private static Locale getLocale() { |
| | | return Locale.ENGLISH; |
| | | } |
| | | |
| | | } |