java - 将纳秒(100 纳秒单位)转换为文件时间并在 java 中查看为日期
问题描述
纳秒值130016196641685504
预期结果:2013 年 1 月 2 日星期三下午 5:01:04
此代码的输出:1974-02-14 01:06:36
FileTime time = FileTime.from(nanoSeconds,TimeUnit.NANOSECONDS);
String pattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
Date date = new Date(time.toMillis());
System.out.println(simpleDateFormat.format(date));
更具体地说,我正在尝试将纳秒转换为 java 中的 humanReadable 格式。有关更多详细信息,请参阅此链接...
解决方案
为什么您会期待 2013 年 1 月 2 日星期三下午 5:01:04?
阅读规格
Parameters:
value - the value since the epoch (1970-01-01T00:00:00Z); can be negative
而 130016196641685504 大约是 4 年。
所以你的期望是错误的。
推荐阅读
- php - PHPword可以用两位小数显示饼图吗?
- reinforcement-learning - 处理大而多变的行动空间
- python - 如何通过 ssh 远程运行 python3 脚本
- r - 如何从月度数据中获取季度变化?
- postgresql - 我们如何在 postgres 中创建每日插入、更新和删除记录的转储文件?
- python - 如何获取两个子字符串之间的字符串?
- reactjs - Highcharts列动画问题
- reactjs - 在 windows 中安装 babel
- angular - 是否可以在多个位置显示角度组件的单个实例?
- ios - OutputStream.write 不会发送完整的数据,而只会发送固定的数量