Java 程式以秒和納秒為單位減去瞬間
讓我們首先設定一個時間
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP