java Date Problem

538 views
Skip to first unread message

Claudio Bisegni

unread,
Jan 7, 2011, 10:21:33 AM1/7/11
to mongodb-user
Hi Folk,
i have a problem with java date this time:
I'making a simple query:
dataQuery.append("$gte", getDateSince());
dataQuery.append("$lte", getDateTol());

query.put("timestamp", dataQuery);

when i am in debugging i can see that Java date object is corret but
when is insert the hour is one hour behind my time. Why MondoObject
make this conversion?

Eliot Horowitz

unread,
Jan 7, 2011, 10:23:02 AM1/7/11
to mongod...@googlegroups.com
You'll have to send the input and outputs for to have any clue what's going on.
Mongo doesn't do anything with time zones, so it might just be a display issue.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Brendan W. McAdams

unread,
Jan 7, 2011, 10:23:26 AM1/7/11
to mongod...@googlegroups.com

Are you sure  it isn't  timezone related? Mongod doesn't store timezone info so your client and server need to be sharing dates in the same timezone.

Claudio Bisegni

unread,
Jan 7, 2011, 10:30:22 AM1/7/11
to mongodb-user
This is the toString() of BasicDBObject;

{ "device_id" : { "$in" : [ 20]} , "timestamp" : { "$gte" :
{ "$date" : "2011-01-05T16:45:00Z"} , "$lte" : { "$date" :
"2011-01-05T16:45:10Z"}}}

and this is the toString of the two date
Wed Jan 05 17:45:10 CET 2011
Wed Jan 05 17:45:00 CET 2011


On Jan 7, 4:23 pm, "Brendan W. McAdams" <bren...@10gen.com> wrote:
> Are you sure  it isn't  timezone related? Mongod doesn't store timezone info
> so your client and server need to be sharing dates in the same timezone.
> On Jan 7, 2011 10:21 AM, "Claudio Bisegni" <cbise...@gmail.com> wrote:> Hi Folk,
> > i have a problem with java date this time:
> > I'making a simple query:
> > dataQuery.append("$gte", getDateSince());
> > dataQuery.append("$lte", getDateTol());
>
> > query.put("timestamp", dataQuery);
>
> > when i am in debugging i can see that Java date object is corret but
> > when is insert the hour is one hour behind my time. Why MondoObject
> > make this conversion?
>
> > --
> > You received this message because you are subscribed to the Google Groups
>
> "mongodb-user" group.> To post to this group, send email to mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to
>
> mongodb-user...@googlegroups.com<mongodb-user%2Bunsubscribe@google groups.com>
> .> For more options, visit this group at
>
> http://groups.google.com/group/mongodb-user?hl=en.
>
>
>
>
>
>
>
>

Keith Branton

unread,
Jan 7, 2011, 10:31:37 AM1/7/11
to mongod...@googlegroups.com
The Z in the Date is GMT (more or less) CET is GMT+1

To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.

Brendan W. McAdams

unread,
Jan 7, 2011, 10:33:33 AM1/7/11
to mongod...@googlegroups.com

Your locality appears to be central european timezone which is +1 against Zulu (gmt) 

As no timezone info is saved with mongo it looks like its being saved against gmt.

Claudio Bisegni

unread,
Jan 7, 2011, 10:36:26 AM1/7/11
to mongodb-user
so it's right that the output is 16???

Keith Branton

unread,
Jan 7, 2011, 10:38:14 AM1/7/11
to mongod...@googlegroups.com
Both values refer to the same date-time, just displayed in different ways. So yes, it's right.

Claudio Bisegni

unread,
Jan 7, 2011, 10:40:48 AM1/7/11
to mongodb-user
so i ahve fault to insert timestamp into db because i use this cose:
statisticData.startCycleTask = microsec_clock::local_time();
statisticData.millisecStartTask = (statisticData.startCycleTask-
EPOCH).total_milliseconds();

and then insert into mongo with
b.appendDate("timestamp", statisticData.millisecStartTask);

with taht in mongodb i see rigth dat.. but in effect is the wrong date
rigth? i have to use only microsec_clock::local_time(); total
millisec?

Keith Branton

unread,
Jan 7, 2011, 10:52:59 AM1/7/11
to mongod...@googlegroups.com
If you generate a date, and display it it will appear in CET because that is the default timezone of your machine.

If you then insert it into mongo and retrieve it, with the java client, and display it again you should still see the same date in CET.


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages