diff options
author | Keuin <[email protected]> | 2021-01-24 20:01:17 +0800 |
---|---|---|
committer | keuin <[email protected]> | 2021-01-24 20:01:17 +0800 |
commit | 5063ab12c48a6612d903c44c943230b6c323f602 (patch) | |
tree | 38ad6cf5f48377142a1d2fabfb1122eb9a681421 /src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java | |
parent | dfd27f1a01a612c39bc17cac9793c80cc9b72e6b (diff) |
Code refactor: eliminate unnecessary instance creation of IncrementalBackupFileNameEncoder
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java b/src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java index bcf5d18..39abc75 100644 --- a/src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java +++ b/src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java @@ -1,32 +1,23 @@ package com.keuin.kbackupfabric.backup; +import com.keuin.kbackupfabric.util.DateUtil; + import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; public class BackupNameTimeFormatter { - private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"); @Deprecated public static String getTimeString() { - return LocalDateTime.now().format(formatter); + return DateUtil.getString(LocalDateTime.now()); } public static String localDateTimeToString(LocalDateTime localDateTime) { - return localDateTime.format(formatter); + return DateUtil.getString(localDateTime); } @Deprecated public static long timeStringToEpochSeconds(String timeString) { - ZoneId systemZone = ZoneId.systemDefault(); // my timezone - LocalDateTime localDateTime = LocalDateTime.parse(timeString, formatter); - ZoneOffset currentOffsetForMyZone = systemZone.getRules().getOffset(localDateTime); - return localDateTime.toEpochSecond(currentOffsetForMyZone); - } - - public static LocalDateTime timeStringToLocalDateTime(String timeString) { - return LocalDateTime.parse(timeString,formatter); + return DateUtil.toEpochSecond(timeString); } } |