java-8 - Java 8:如何将时间戳转换为长
问题描述
我正在编写后端服务并接收时间戳,如下所示
Instant timestamp = Instant.now().plusMillis(offset);
bodyObject.put("timestamp", DateTimeFormatter.ISO_INSTANT.format(timestamp));
现在在我的服务端,我想将此时间戳转换为"Long"
数据类型以供进一步处理。请指导我如何实现这一目标?
解决方案
我正在将时间戳格式转换为Instant
然后使用getEpochSecond()
方法来获取秒数
Instant instant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(format));
instant.getEpochSecond();
推荐阅读
- java - if 语句中的多个条件 - first 始终为真
- php - 使用 Guzzle 上传带有文件的数据 - Laravel
- reactjs - 为反应库配置汇总
- c# - 托管标识 - 如何在本地调试
- reactjs - React-Bootstrap v1 中的 Panel.Collapse
- android - 禁用 FRP 的用户帐户,仅允许工作管理帐户
- python - Python 3:删除文件中最后一个字符的惯用方法
- javascript - WebStorm diff 中一行上的黄色块是什么意思?
- ios - ios上的cordova cli命令失败:ENOENT cordova-config.json.SOME_NUMBER
- python - select appropriate dataframe based on user input