From ac7e70883c18602e7fd4b525b9e6fb9ea9620a6b Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 20 Jan 2021 19:50:42 +0800 Subject: refactor --- .../backup/BackupNameTimeFormatter.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java (limited to 'src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java') diff --git a/src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java b/src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java new file mode 100644 index 0000000..bcf5d18 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/backup/BackupNameTimeFormatter.java @@ -0,0 +1,32 @@ +package com.keuin.kbackupfabric.backup; + +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); + } + + public static String localDateTimeToString(LocalDateTime localDateTime) { + return localDateTime.format(formatter); + } + + @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); + } + +} -- cgit v1.2.3