--- /dev/null
+package de.example.date.parsing;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Date;
+
+
+public class DateFormatUtils {
+
+ public static String format(Date date, String format) {
+ final ZoneId timeZone = ZoneId.of("America/Los_Angeles");
+
+ return DateFormatUtils.format(date, format, timeZone);
+ }
+
+ public static String format(Date date, String format, ZoneId timeZone) {
+ final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
+ final Instant instantDate = Instant.ofEpochMilli(date.getTime());
+ final LocalDateTime localDateTime = LocalDateTime.ofInstant(instantDate, timeZone);
+
+ return localDateTime.format(formatter);
+ }
+
+ public static Date parse(String text, String format) {
+ final ZoneId timeZone = ZoneId.of("America/Los_Angeles");
+
+ return DateFormatUtils.parse(text, format, timeZone);
+ }
+
+ public static Date parse(String text, String format, ZoneId timeZone) {
+ final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
+ final LocalDateTime dateTimeJava8 = LocalDateTime.parse(text, formatter);
+
+ return Date.from(dateTimeJava8.atZone(timeZone).toInstant());
+ }
+}
--- /dev/null
+package de.example.date.parsing;
+
+import java.util.Date;
+
+
+public class DateHourFormatter {
+
+ public static final String DATE_FORMAT = "dd/MM/yyyy HH:mm";
+
+ private DateHourFormatter() {
+ }
+
+ public static String formatToDateTime(Date date) {
+ if (date == null) {
+ return "";
+ }
+ return DateFormatUtils.format(date, DATE_FORMAT);
+ }
+
+ public static Date parseToDate(String text) {
+ return DateFormatUtils.parse(text, DATE_FORMAT);
+ }
+
+}
--- /dev/null
+package de.example.date.parsing;
+
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Date;
+
+
+public class MainDateFormat {
+
+ public static void main(String[] args) {
+
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
+ ZoneId timeZone = ZoneId.of("America/Los_Angeles");
+
+ // Just date without minutes and seconds.
+ LocalDate dateJava8 = LocalDate.parse("12/05/2014 18:40", formatter);
+ Date date = Date.from(dateJava8.atStartOfDay().atZone(timeZone).toInstant());
+
+ // Date with minutes and seconds.
+ LocalDateTime dateTimeJava8 = LocalDateTime.parse("12/05/2014 18:40", formatter);
+ Date dateTime = Date.from(dateTimeJava8.atZone(timeZone).toInstant());
+
+ Date now = new Date();
+ Instant instant = Instant.ofEpochMilli(now.getTime());
+ LocalDateTime currentLocalDateTime = LocalDateTime.ofInstant(instant, timeZone);
+ String currentTime = currentLocalDateTime.format(formatter);
+
+ String dateHourCurrentTimeFormatter = DateHourFormatter.formatToDateTime(now);
+
+
+ Date dateCurrentTimeFormatter = DateHourFormatter.parseToDate("12/05/2014 18:40");
+ }
+
+}