aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper/DateUtil.java
diff options
context:
space:
mode:
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);
+ }
}
}