String Groovy:将字符串转换为整数会产生NumberFormatException
我正在尝试从以下文本中获取日期: {InstantSeconds=1581504140},ISO,欧洲/巴黎,决议于2020-02-12T11:42:20 我试过了String Groovy:将字符串转换为整数会产生NumberFormatException,string,groovy,int,String,Groovy,Int,我正在尝试从以下文本中获取日期: {InstantSeconds=1581504140},ISO,欧洲/巴黎,决议于2020-02-12T11:42:20 我试过了 def text = "{InstantSeconds=1581504140},ISO,Europe/Paris resolved to 2020-02-12T11:42:20" text = text.replaceAll("[^\\d.]", "") text = text.substring(10) println "${te
def text = "{InstantSeconds=1581504140},ISO,Europe/Paris resolved to 2020-02-12T11:42:20"
text = text.replaceAll("[^\\d.]", "")
text = text.substring(10)
println "${text}"
int result= Integer.parseInt("${text}");
println result
但是我越来越
java.lang.NumberFormatException:用于输入字符串:“2020021120”
我正在用这个(练习)
有人知道为什么会这样吗?该值对于整数来说太长。使用长数据类型:
Long result = text.toLong()
assert result.class.name == 'java.lang.Long'
assert result == 20200212114220