java - Joda-Time, How to pick up format for string parsing? -


following code using joda-time library

long timestamp = datetime.parse(dateinstring,datetimeformat.shorttime()).getmillis(); 

generates:

java.lang.illegalargumentexception: invalid format: "12.05.2014 11:42:35.808" malformed @ ".05.2014 11:42:35.808" 

i tryed datetimeformat.* each format produces error.

how fix it?

build datetimeformatter matching pattern, , use that. pattern isn't "short time" pattern, given you've got date in there well...

for example:

// possibly mm.dd.yyyy - don't know 12.05.2014 meant represent datetimeformatter formatter = datetimeformat.forpattern("dd.mm.yyyy hh:mm:ss.sss");                                             .withlocale(locale.us)                                             .withzoneutc(); // adjust accordingly datetime datetime = formatter.parse(text); long millis = datetime.getmillis(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -