diff options
Diffstat (limited to 'juick-core/src/main/java/com/juick/util')
-rw-r--r-- | juick-core/src/main/java/com/juick/util/DateFormatter.java | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/juick-core/src/main/java/com/juick/util/DateFormatter.java b/juick-core/src/main/java/com/juick/util/DateFormatter.java index d7cf16bf..f9e23a91 100644 --- a/juick-core/src/main/java/com/juick/util/DateFormatter.java +++ b/juick-core/src/main/java/com/juick/util/DateFormatter.java @@ -19,10 +19,11 @@ package com.juick.util; import org.apache.commons.lang3.StringUtils; +import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import java.util.Date; +import java.util.Locale; /** * Created by aalexeev on 12/7/16. @@ -31,25 +32,25 @@ public class DateFormatter { private final DateTimeFormatter formatter; public DateFormatter(String pattern) { - formatter = DateTimeFormatter.ofPattern(pattern); + formatter = DateTimeFormatter.ofPattern(pattern, Locale.ENGLISH); } - public String format(final Date date) { - if (date == null) + public String format(final Instant ts) { + if (ts == null) return null; - LocalDateTime ldt = LocalDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC); + LocalDateTime ldt = LocalDateTime.ofInstant(ts, ZoneOffset.UTC); return ldt.format(formatter); } - public Date parse(final String v) { + public Instant parse(final String v) { if (StringUtils.isBlank(v)) return null; LocalDateTime ldt = LocalDateTime.parse(v, formatter); - return Date.from(ldt.toInstant(ZoneOffset.UTC)); + return ldt.toInstant(ZoneOffset.UTC); } } |