private static String datePattern = "yyyy-MM-dd HH:mm:ss.SSS";
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern(datePattern);
long current = System.currentTimeMillis();
SimpleDateFormat format = new SimpleDateFormat(datePattern);
String time = format.format(current);
LocalDateTime localDateTime = LocalDateTime.parse(time, formatter);
ArrayList<Long> ts = new ArrayList<>();
ts.add(localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() * 1000000 );
最终展示的时间格式
select * from d1 limit 10 ;
ts | current | voltage | phase |
============================================================================================
2023-07-19 23:42:27.294000000 | 10.3000002 | 219 | 0.3100000 |
纳秒不能使用 System.nanoTime() 计算 而应该转换为 公元1970 那个utc 时间的差值,在毫秒的基础上 * 1000000 就是纳秒