I was making a small code to implement a treatment case in a friend application module and got stuck with a problem.
This is a unit test. To put in the application module I would have to make some adjustments when inserting into the native code of it, but basically I'm getting a String
from a database in the format similar to the String
given below:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String args[]) throws ParseException {
String value = "2018-4-25 0.0.0.0 -3:00";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy HH:mm:ss");
if (value.charAt(6) == '-') {
SimpleDateFormat myformat = new SimpleDateFormat("yyyy-M-dd H.m.s.S X");
Date d1 = myformat.parse(value);
String result = sdf.format(d1);
result = result + ", " + "000000000 " + "-03:00";
System.out.println(result);
} else {
SimpleDateFormat myformat = new SimpleDateFormat("yyyy-MM-dd H.m.s.S X");
Date d1 = myformat.parse(value);
String result = sdf.format(d1);
result = result + ", " + "000000000 " + "-03:00";
System.out.println(result);
}
}
}
But the message I get is:
"C:\Program Files\Java\jdk-10.0.1\bin\java.exe" "-javaagent:C:\Program Files (x86)\IntelliJ IDEA\lib\idea_rt.jar=63052:C:\Program Files (x86)\IntelliJ IDEA\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\...\IdeaProjects\untitled\out\production\untitled Main
Exception in thread "main" java.text.ParseException: Unparseable date: "2018-4-25 0.0.0.0 -3:00"
at java.base/java.text.DateFormat.parse(DateFormat.java:395)
at Main.main(Main.java:23)
Process finished with exit code 1
Could anyone help me?