Reputation: 10631
I have this long 1383903835525 but need to append L for Java to recognize it as a long otherwise I get the 'int is too long' error
So the en result will be 1383903835525L
public String getDate(long milliseconds) {
setDateFormat();
return getResult(milliseconds);
}
this works
date.getDate(1383903835525L);
but the server is sending me back this in the response 1383903835525
Should the server rather send back 1383903835525L ?
Upvotes: 1
Views: 3055
Reputation: 709
If the server response is a string, you can convert it to a long by calling Long.parseLong(string).
Long.parseLong(milliseconds);
Upvotes: 4
Reputation: 4707
The server most probably returns 1383903835525
as String
. Even if it's not String
, it is a legal long
value.
However, when you write a number literal in your code, it is always assumed as int
, hence the "int is too long" error. Thus, you have to explicitly declare the number as long
by appending L
. (i.e. 1383903835525L
)
Upvotes: 2