繁体   English   中英

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

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

我正在尝试使用以下代码将系统时间转换为int

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

但我收到以下错误:

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

为什么这个数字: "1538956627792"仍然抛出错误?

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

long todayInt = Long.parseLong(today);

int类型的大小为 32 位,范围从-2,147,483,6482,147,483,647 1538956627792超出范围,所以造成的错误。

你可以把int改成long来解决这个问题,这里有详细的参考

暂无
暂无

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

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