java - Using Joda-Time to form correct ISODate for Mongo insert -


i trying update date fields in mongo require isodate format. in mongo, looks this:

"crdt" : isodate("2013-08-19t17:21:57.549z") 

the java framework using has me restricted using strings test parameters, trying use string datetimeformatter correct isodatetimeformat , pass mongo. cannot pass in string looks have above. trying screws field in mongo. relevant bits of joda-time code using this:

//i can't right. string crdt = "2013-01-19t15:28:58.851z";  datetimeformatter parser = isodatetimeformat.datehourminutesecondmillis();  parser.parsedatetime(crdt);  // method updates record in mongo. method totally works, no  // point in pasting here, can't parser object correct  // in correct format once inserted, needs correct isodate form. mongo.setcrdt(recordid, parser); 

and when code runs errors these .parsedatetime method:

java.lang.illegalargumentexception: invalid format: "2013-01-19t15:28:58.851z" malformed @ "z"     @ org.joda.time.format.datetimeformatter.parsedatetime(datetimeformatter.java:866) 

i can tell string giving not correct things parsed. i've tried leaving off z, i've tried other combos, each time says it's malformed. basically, starting string need to .parsedatetime work , give me object looks correct?

edit:

updated try suggestions provided below. issue run illegalargumentexception, can't serialize class org.joda.time.datetime. appears persisting joda time objects in no-go? looked @ other suggestion, looking mapper frameworks spring data. looks there whole lot more needs go this. there no simple way persist mongo?

edit2:

ok, think have now. might not have total grasp of mechanics @ play, basicdbobjects won't play nice datetime. date objects seem way go, @ least in implementation i'm dealing with. did following:

datetimeformatter parser = isodatetimeformat.datetime(); datetime result; date newresult; result = parser.parsedatetime(crdt); newresult = result.todate(); 

i passed in newresult basicdbobject update record in mongo. works fine, , record updated correctly.

your input string format correct, long is intended represent utc.

change parser use 1 matches format:

datetimeformatter parser = isodatetimeformat.datetime(); 

the rest of question doesn't make sense me. shouldn't pass parser, rather return value parsedatetime, don't appear capturing.

datetime result = parser.parsedatetime(crdt);  mongo.setcrdt(recordid, result.todate()); 

whether or not last line work depends on function accepts.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -