java - jodatime -> parse error utc datetime string -


currently, i'm trying parse datetime using jodatime library.

string stringliteral = "09/05/2016 12:25:39" try {   datetime utcdatetime = new datetime(stringliteral, datetimezone.utc);   this.expressiontype = expressionenumtype.date;   this.expressions.add(constantimpl.create(utcdatetime.todate())); } catch (illegalargumentexception e) {   this.expressiontype = expressionenumtype.string;   this.expressions.add(constantimpl.create(stringliteral)); } 

however, jodatime tells me:

java.lang.illegalargumentexception: invalid format: "09/05/2016 12:25:39" malformed @ "/05/2016 12:25:39"

the constructor of datetime cannot parse string in arbitrary format datetime object. if want use constructor in way, string must in 1 of iso 8601 formats, , string "09/05/2016 12:25:39" not.

use method parse date, can specify format yourself. example:

datetimeformatter formatter = datetimeformat.forpattern("dd/mm/yyyy hh:mm:ss")                                             .withzoneutc();  datetime utcdatetime = datetime.parse(stringliteral, formatter); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -