0

I'm new to MONGO DB. I have problem when storing date like "2016-07-22T11:22:48+01:00" in java. how could i set format to save this kind of date using Java ?

this is my code sample

I want to add date like "2016-07-22T11:22:48+01:00". So i used following code in Java.

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date lastmod = sdf.parse(lastmod_date);

then i used DBObject to save date to mongodb. used following code sample

sitemapObject.put("lastmod_date", lastmod);
Amal Madawa
  • 187
  • 1
  • 14
  • 2
    Possible duplicate of [date in MongoDB: when inserting Date objects into Mongo database, the date becomes 1 day earlier than itself](http://stackoverflow.com/questions/11815155/date-in-mongodb-when-inserting-date-objects-into-mongo-database-the-date-becom) – ruhungry Jul 22 '16 at 10:29
  • 2
    An OffsetDateTime would be a good match: `OffsetDateTime.parse("2016-07-22T11:22:48+01:00");`. – assylias Jul 22 '16 at 10:49
  • 2
    Mongo can store ISO date/time values internally. If you have problems coping with that in Java, post your code and describe the concrete problem. – mtj Jul 22 '16 at 11:13

0 Answers0