管灌系统巡查员智能手机App
app/src/main/java/com/dayu/pipirrapp/utils/DateUtils.java
@@ -31,15 +31,25 @@
    /**
     * 返回统一格式的当前时间截止到分钟
     *
     * @return yyyy-MM-dd HH:mm:ss
     * @return yyyy-MM-dd HH:mm
     */
    public static String getNowDateToMMStr() {
        // 当前时间
        Date date = new Date();
        // 创建 SimpleDateFormat 对象,设置日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
        // 格式化当前时间为字符串
        return sdf.format(date);
    }
    /**
     * 将时间戳转换为指定格式的字符串
     * @param timestamp 时间戳
     * @return 格式化后的时间字符串 (yyyy-MM-dd HH:mm)
     */
    public static String formatTimestamp(long timestamp) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
        return sdf.format(new Date(timestamp));
    }
}