Reputation: 31
I have this weird format of date and time on my Oracle SQL Developer :
2015-4-14.1.39. 33. 870000000
I tried to format the given date to MM-dd-yyyy HH:mm:ss
, but it gives me exception:
java.text.ParseException: Unparseable date: "2015-4-14.1.39. 33. 870000000"
The following is the code:
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
try {
String ts = "2015-4-14.1.39. 33. 870000000";
Date date = formatter.parse(ts);
String S = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(date);
System.out.println(S);
} catch (Exception e) {
e.printStackTrace();
}
Upvotes: 0
Views: 229
Reputation: 29468
The problem is that the given date string does not match the specified format. Try use the following format:
SimpleDateFormat df = new SimpleDateFormat("yyyy-M-dd.H.m. s. S");
String ts = "2015-4-14.1.39. 33. 870000000";
df.parse(ts);
Where
yyyy
for yearM
for month in yeardd
for day in monthH
for hour in date (0-23)m
for minute in hours
for second in minuteS
for millisecondUpvotes: 1