convert with simple date formatting

This commit is contained in:
mherbaghinyan 2019-03-24 11:08:54 +04:00
parent 2d3ac05704
commit 6c6e9ed53d
1 changed files with 24 additions and 1 deletions

View File

@ -4,16 +4,39 @@ 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;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
public class ConvertDateTime {
public static void main(String[] args) {
public static void main(String[] args) throws ParseException {
java8();
joda();
Date date = simpleDateTimeFormatter();
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";
Date date = sdf.parse(dateInString);
System.out.println(dateInString);
System.out.println("Date - Time in milliseconds : " + date.getTime());
return date;
}
private static void joda() {