blob: bcf5d18e1221fc86d73757d4d198b676717ccf8c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
}
}
|