Java程序从Instant减少到几秒和十亿分之一秒
让我们首先设置一个Instant:
Instant now = Instant.ofEpochMilli(184142540078l);
现在让我们减去Instant的秒数:
Instant resSeconds = now.minusSeconds(50);
现在让我们减去Instant的十亿分之一秒:
Instant resNanoSeconds = now.minusNanos(10000);
示例
import java.time.Instant;
public class Demo {
public static void main(String[] args) {
Instant now = Instant.ofEpochMilli(184142540078l);
System.out.println(now);
Instant resSeconds = now.minusSeconds(50);
System.out.println("After subtracting seconds = "+resSeconds);
Instant resNanoSeconds = now.minusNanos(10000);
System.out.println("After subtracting nanoseconds = "+resNanoSeconds);
}
}输出结果
1975-11-02T06:42:20.078Z After subtracting seconds = 1975-11-02T06:41:30.078Z After subtracting nanoseconds = 1975-11-02T06:42:20.077990Z
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短