java - Change timezone of date before sending to MonngoDB -
i querying mongo db below query
query: { "modifieddate" : { "$lt" : { "$date" : "2016-01-20t05:08:28.000z"}}
this date in modifieddate
provided backend ui in long format has value 1453286308000.
long date converted date object using below line
datetime(value).withzone(datetimezone.forid(timezoneid)).todate()
returned date class object of value "2016-01-20 10:38:28"
. want date in utc format before querying mongodb. mongo query,
criteria.where(modified_date).lt(date)
date object coming in query "2016-01-20t05:08:28."
not "2016-01-20 10:38:28"
expected.
this 5.30
hrs difference caused because date considering local timezone. possible avoid it.
i tried using
calendar cal = gregoriancalendar.getinstance(timezone.gettimezone("utc")); cal.settimeinmillis(value + timezone.getdefault().getrawoffset());
which gives me expected result. there better approach or work in scenarios?
Comments
Post a Comment