简体   繁体   English

java.lang.NumberFormatException:对于输入字符串:“1538956627792”

[英]java.lang.NumberFormatException: For input string: "1538956627792"

I'm trying to convert the system time to int with the following code:我正在尝试使用以下代码将系统时间转换为int

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?为什么这个数字: "1538956627792"仍然抛出错误?

数字太长,无法解析为int ,您需要使用Long来解析那个大数字,

long todayInt = Long.parseLong(today);

The size of int type is 32 bit, it ranges from -2,147,483,648 to 2,147,483,647 . int类型的大小为 32 位,范围从-2,147,483,6482,147,483,647 1538956627792 exceeds the range, so the error caused. 1538956627792超出范围,所以造成的错误。

you could change int to long to solve this problem, here is a detailed reference你可以把int改成long来解决这个问题,这里有详细的参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM