HW4 – DateTime Parse
private static final SimpleDateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
// use comma as separator
String[] items = line.split(delimiter);
Date dateTime = null;
try {
dateTime = formatter.parse(items[0]);
}
catch (ParseException e) {
e.printStackTrace();
}
/////////////////////////DateParseTest.java////////////////////////////////////////
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.io.FileNotFoundException;
import java.util.*;
public class DateParseTest {
private static final SimpleDateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
public static void main(String[] args) {
String date=”1980-12-29 13:00:06″;
Date dateTime = null;
try {
dateTime = formatter.parse(date);
}
catch (ParseException e) {
e.printStackTrace();
}
System.out.println(formatter.format(dateTime));
}
}