首先,您需要将代表 纳秒 的 数字 转换为 毫秒 。
然后,对于给定的日期字符串,获取自unix时间 Epoch 以来的总毫秒数,然后向其添加更早转换为毫秒的数字。
这是工作代码:
String target = "1904/01/01 12:00 AM"; // Your given date stringlong nanoseconds = ...; // nanoseconds since target time that you want to convert to java.util.Datelong millis = TimeUnit.MILLISECONDS.convert(nanoseconds, TimeUnit.NANOSECONDS);DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd hh:mm aaa");formatter.setTimeZone(TimeZone.getTimeZone("UTC"));Date date = formatter.parse(target);long newTimeInmillis = date.getTime() + millis;Date date2 = new Date(newTimeInmillis);System.out.println(date2);添加一个
import java.util.concurrent.TimeUnit;。



