Nick H
Nick H

Reputation: 8992

Javascript/Java - Webservice returning doubles for date.valueOf()

I have a javascript webservice that returns an array of timestamps using date.valueOf().

But for some reason when my Android application gets the results they are all doubles! Why is this happening? I have confirmed the array in the webservice is loaded with non double values!

Upvotes: 0

Views: 34

Answers (1)

Adam Axtmann
Adam Axtmann

Reputation: 236

valueOf() returns the primitive value of a Date object, so the double you're seeing is the date expressed in milliseconds since midnight 01 January, 1970 UTC. This is also known as epoch time.

If you want the date in some other format, you should probably look at the documentation for getFullYear, getMonth, and getDate, which you could use to construct a string for the date.

Alternatively, Java has a Calendar class which has functions to convert from epoch time to regular dates.

Upvotes: 1

Related Questions