2
I was making a little code to implement a treatment case in a friend’s application module and got stuck with a problem.
This is a unitary test. To put in the application module I would have to make some adjustments when entering in his native code, but basically I’m getting one String
of a database in a format similar to 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 someone help me?
Our language is the Português, translate your question.
– user28595
Sorry, I hadn’t noticed q is in en Anyway, it’s a code that I get a string from a database and need to convert to Date. However, the parse is not going well. That’s what I don’t understand
– Al Zarus
Translate your question first, otherwise it will be closed.
– user28595
Ready! Thank you!
– Al Zarus