You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by vsriram30 <vs...@gmail.com> on 2015/02/19 20:19:00 UTC

Solr date retrieve back UTC

Hi,

I am having a date field in my solr schema and I am indexing a proper UTC
date to that field. If I am directly querying Solr, I am able to see the
field with UTC time in that in the JSON response.

But when I use SolrJ and get it as object, I am seeing that the UTC date is
of type Date and I am not able to retrieve back the UTC date from it and I
get only long timestamp from that object.

I also see a private variable in that Date class called as cDate which has
what I want (Date in UTC format). But I am not able to get the UTC value out
of that variable. Is there any better ways to get UTC timestamp out of that
field?

Thanks,
Sriram



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-date-retrieve-back-UTC-tp4187449.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr date retrieve back UTC

Posted by vsriram30 <vs...@gmail.com>.
Thanks Chris for additional info.

Thanks,
Sriram



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-date-retrieve-back-UTC-tp4187449p4187503.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr date retrieve back UTC

Posted by Chris Hostetter <ho...@fucit.org>.
: to get the UTC back which I thought might not be required as already the
: cDate field in that Date class is having the UTC date.

general suggestion: your life will be a lot easier if you stop looking at 
the implementation details of JVM classes -- just because your current JVM 
implements the Date class with some internal "cDate" field doesn't mean 
that the next JVM release (or some JVM sold by another company) will be 
implemented the same way.

: The toString() doesn't actually give me timestamp in UTC format. It gives,

the representation returned by toString() is entirely dependent on your 
locale.  please read my comment fully.  there are *LOTS* of tutorials on 
the internet about dealing with Date & DateFormat objects in java...


>> Date objects in Java do not have any intrinsic TimeZone -- they 
>> represent absolute fixed moments in time.  to "see" a Date in UTC (or 
>> any other time zone) you must convert it to a String -- either by using 
>> hte detault "toString()" representation, or by using a DateFormat.



-Hoss
http://www.lucidworks.com/

Re: Solr date retrieve back UTC

Posted by vsriram30 <vs...@gmail.com>.
Thanks Chris for your quick reply. As you said, I need to do some conversion
to get the UTC back which I thought might not be required as already the
cDate field in that Date class is having the UTC date.

The toString() doesn't actually give me timestamp in UTC format. It gives,

Mon Sep 15 12:52:08 PDT 2014

Thanks,
V.Sriram



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-date-retrieve-back-UTC-tp4187449p4187456.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr date retrieve back UTC

Posted by Chris Hostetter <ho...@fucit.org>.
: But when I use SolrJ and get it as object, I am seeing that the UTC date is
: of type Date and I am not able to retrieve back the UTC date from it and I
: get only long timestamp from that object.
: 
: I also see a private variable in that Date class called as cDate which has
: what I want (Date in UTC format). But I am not able to get the UTC value out
: of that variable. Is there any better ways to get UTC timestamp out of that
: field?

Date objects in Java do not have any intrinsic TimeZone -- they represent 
absolute fixed moments in time.  to "see" a Date in UTC (or any other 
time zone) you must convert it to a String -- either by using hte detault 
"toString()" representation, or by using a DateFormat.




-Hoss
http://www.lucidworks.com/