Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中将字符串转换为即时字符串_Java - Fatal编程技术网

在Java中将字符串转换为即时字符串

在Java中将字符串转换为即时字符串,java,Java,我对java很陌生。我想将格式为“1558337076000+0000”的字符串转换为Instant。 我尝试了Instant.parse(“1558337076000+0000”),但这引发了一个异常。我可以在这里获得一些帮助吗?根据Javadoc,您传入的字符串必须满足特定的要求 字符串必须表示UTC中的有效瞬间,并使用DateTimeFormatter.ISO_instant进行解析 DateTimeFormatter.ISO_INSTANT的示例是2011-12-03T10:15:30Z

我对java很陌生。我想将格式为“1558337076000+0000”的字符串转换为Instant。
我尝试了
Instant.parse(“1558337076000+0000”)
,但这引发了一个异常。我可以在这里获得一些帮助吗?

根据Javadoc,您传入的字符串必须满足特定的要求

字符串必须表示UTC中的有效瞬间,并使用DateTimeFormatter.ISO_instant进行解析

DateTimeFormatter.ISO_INSTANT的示例是
2011-12-03T10:15:30Z


通过查看您的字符串(现在是凌晨3点…)我无法判断这是毫秒还是秒,但我建议使用适当的
ofEpochMilli
ofEpochSecond
。首先需要使用
long.parseLong()
将字符串转换为long,这将涉及删除尾随的
+0000
,因为这是无效的
long
格式。

去掉
+0000
,将数字解析为long。那么,异常说明了什么?“…文本字符串,如2007-12-03T10:15:30.00Z。该字符串必须表示UTC中的有效瞬间,并使用DateTimeFormatter.ISO_instant进行解析。”-来自