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
Post a Comment