如何解决在Java中将ISO 8601时间戳字符串转换为纪元秒
我收到ISO 8601日期时间格式2020-11-03T15:23:24.388Z
的字符串。在Java中将其转换为时代秒的最佳方法是什么?
解决方法
使用see here for the example,您可以如下所示进行操作:
List<Long>nex= new ArrayList<>();
for(int i=0;i<result.size();i++){
if(Long.valueOf(result.get(i))>n){
nex.add(Long.valueOf(result.get(i)));
}
}
输出:
import java.time.Instant;
public class Main {
public static void main(String[] args) {
Instant instant = Instant.parse("2020-11-03T15:23:24.388Z");
long seconds = instant.getEpochSecond();
System.out.println(seconds);
}
}
如果您正在为自己的Android项目执行此操作,并且您的Android API级别仍不符合Java-8,请选中modern date-time API和Java 8+ APIs available through desugaring。
通过 How to use ThreeTenABP in Android Project 了解有关现代日期时间API的更多信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。