Skip to content
Advertisement

java.lang.NumberFormatException: For input string: “1538956627792”

I’m trying to convert the system time to int with the following code:

String today = "" + System.currentTimeMillis();
int todayInt = Integer.parseInt(today);

But I’m getting the following error:

java.lang.NumberFormatException: For input string: "1538956627792"

Why is this number: "1538956627792" still throwing an error?

Advertisement

Answer

Number is too long to be parsed as int, You need to use Long to parse that big number,

long todayInt = Long.parseLong(today);
Advertisement