From 08ac6aaea58b7309ea95a12ca6227a6ca3ce4db5 Mon Sep 17 00:00:00 2001 From: Keuin Date: Mon, 25 Jan 2021 15:25:34 +0800 Subject: Improve user interaction. Code refactor. --- src/main/java/com/keuin/kbackupfabric/util/DateUtil.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main/java/com/keuin/kbackupfabric/util/DateUtil.java') diff --git a/src/main/java/com/keuin/kbackupfabric/util/DateUtil.java b/src/main/java/com/keuin/kbackupfabric/util/DateUtil.java index b101cfd..7111347 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/DateUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/DateUtil.java @@ -1,13 +1,18 @@ package com.keuin.kbackupfabric.util; +import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.util.Date; public class DateUtil { + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"); + private static final SimpleDateFormat outFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final DateTimeFormatter prettyFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); public static String getString(LocalDateTime localDateTime) { return localDateTime.format(formatter); @@ -28,4 +33,12 @@ public class DateUtil { public static LocalDateTime toLocalDateTime(String timeString) { return LocalDateTime.parse(timeString, formatter); } + + public static String fromEpochMillis(long epochMillis) { + return outFormatter.format(new Date(epochMillis)); + } + + public static String getPrettyString(LocalDateTime localDateTime) { + return prettyFormatter.format(localDateTime); + } } -- cgit v1.2.3