java处理纳秒时间

//将日志中带有纳秒时间转成纳秒时间戳
String input = "2023-02-06T10:28:49.754400463+08:00";
DateTimeFormatter f = DateTimeFormatter.ofPattern( "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSXXX");
f.withZone(TimeZone.getTimeZone("GMT+8").toZoneId());
LocalDateTime ldt = LocalDateTime.parse(input , f) ;
long timestamp = ldt.toEpochSecond(ZoneOffset.of("+8")) * 1_000_000_000 + ldt.getNano();
System.out.println(timestamp);

你可能感兴趣的:(java基础,java)