mm martin
mm martin

Reputation: 19

How to get the datetime from NumberLong

I received a JSON field from mondb:

"publishDate": NumberLong("1500948351000"),

I try to parse it as this in Java:

String docTime = new DateTime(jsonDoc.getLong(publishDate)).toString();

But receive an exception:

org.json.JSONException: JSONObject["publishDate"] is not a long.

How to retrieve the datetime from the NumberLong?

Upvotes: 0

Views: 318

Answers (1)

Tom
Tom

Reputation: 3346

'NumberLong("1500948351000")' is not a long.

String aa = jsonDoc.getString(publishDate) 

is probably the String with value NumberLong("1500948351000"). And then you can use

String longString = aa.subString(aa.indexOf("\"") + 1, aa.lastIndexOf("\""));
long pbDate = Long.parseLong(longString);

to obtain the long value.

Upvotes: 1

Related Questions