aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper/DateUtil.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-11-08 13:37:38 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2018-11-08 13:37:38 +1300
commit9c9370f72c51d7466d3b25a59264ee98f4319b3a (patch)
tree1fca14e8a624e79f86b913dc60f94a93513a8eb0 /src/org/traccar/helper/DateUtil.java
parent81d2b86ac7cca874b32c94fffa28b902c6fb0eca (diff)
downloadtrackermap-server-9c9370f72c51d7466d3b25a59264ee98f4319b3a.tar.gz
trackermap-server-9c9370f72c51d7466d3b25a59264ee98f4319b3a.tar.bz2
trackermap-server-9c9370f72c51d7466d3b25a59264ee98f4319b3a.zip
Fix time formatting issues
Diffstat (limited to 'src/org/traccar/helper/DateUtil.java')
-rw-r--r--src/org/traccar/helper/DateUtil.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/org/traccar/helper/DateUtil.java b/src/org/traccar/helper/DateUtil.java
index e09ac6d0e..20a483e3c 100644
--- a/src/org/traccar/helper/DateUtil.java
+++ b/src/org/traccar/helper/DateUtil.java
@@ -15,9 +15,10 @@
*/
package org.traccar.helper;
-import org.traccar.Context;
-
+import java.text.SimpleDateFormat;
import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
@@ -59,7 +60,19 @@ public final class DateUtil {
}
public static Date parseDate(String value) {
- return Date.from(Instant.from(Context.DATE_FORMATTER.parse(value)));
+ return Date.from(Instant.from(DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(value)));
+ }
+
+ public static String formatDate(Date date) {
+ return formatDate(date, true);
+ }
+
+ public static String formatDate(Date date, boolean zoned) {
+ if (zoned) {
+ return DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.systemDefault()).format(date.toInstant());
+ } else {
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
+ }
}
}