Skip to content

Commit

Permalink
convert final
Browse files Browse the repository at this point in the history
  • Loading branch information
MherBaghinyan committed Apr 4, 2019
1 parent 6c6e9ed commit 3b43bdd
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions java-dates/src/main/java/com/baeldung/convert/ConvertDateTime.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.baeldung.convert;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
Expand All @@ -22,35 +18,32 @@ public static void main(String[] args) throws ParseException {
calendar(date);
}

private static void calendar(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
System.out.println("Calender - Time in milliseconds : " + calendar.getTimeInMillis());
}

private static Date simpleDateTimeFormatter() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
String dateInString = "22-01-2015 10:20:56";
String dateInString = "22-04-2019 10:20:56";
Date date = sdf.parse(dateInString);

System.out.println(dateInString);
System.out.println("Date - Time in milliseconds : " + date.getTime());

return date;
}

private static void calendar(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
System.out.println("Calender - Time in milliseconds : " + calendar.getTimeInMillis());
}

private static void joda() {
String s = "00:00:01.2";
DateTimeFormatter format = DateTimeFormat.forPattern("HH:mm:ss.S");
DateTime dateTime = format.parseDateTime(s);
System.out.println(dateTime.getMillisOfSecond());
org.joda.time.DateTime jodaDateTime = new org.joda.time.DateTime(new Date());
long delta = jodaDateTime.getMillis();
System.out.println("Joda - Time in milliseconds : " + delta);
}

private static void java8() {
LocalDateTime localDateTime = LocalDateTime.now();

ZoneId id = ZoneId.systemDefault();
ZonedDateTime zdt = ZonedDateTime.of(localDateTime, id);
System.out.println(zdt.toInstant().toEpochMilli());
System.out.println("Java 8 - Time in milliseconds : " + zdt.toInstant().toEpochMilli());
}
}

0 comments on commit 3b43bdd

Please sign in to comment.