mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-27 06:42:05 +01:00
Make DateUtil thread-safe
This commit is contained in:
parent
bb27fddc89
commit
ccc62e090c
1 changed files with 7 additions and 5 deletions
|
@ -25,9 +25,11 @@ public final class DateUtil {
|
||||||
private DateUtil() {
|
private DateUtil() {
|
||||||
|
|
||||||
}
|
}
|
||||||
public static SimpleDateFormat UTC_PARSER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
|
|
||||||
static {
|
public static SimpleDateFormat getParser() {
|
||||||
UTC_PARSER.setTimeZone(TimeZone.getTimeZone("UTC"));
|
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
|
||||||
|
parser.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,7 +40,7 @@ public final class DateUtil {
|
||||||
*/
|
*/
|
||||||
public static Date parseUTCDate(String dateString) {
|
public static Date parseUTCDate(String dateString) {
|
||||||
try {
|
try {
|
||||||
return UTC_PARSER.parse(dateString);
|
return getParser().parse(dateString);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +53,7 @@ public final class DateUtil {
|
||||||
* @return timestamp
|
* @return timestamp
|
||||||
*/
|
*/
|
||||||
public static String formatUTCDate(Date date) {
|
public static String formatUTCDate(Date date) {
|
||||||
return UTC_PARSER.format(date);
|
return getParser().format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue