- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to minus seconds and nanoseconds from Instant
Let us first set an Instant:
Instant now = Instant.ofEpochMilli(184142540078l);
Let us now minus seconds from Instant:
Instant resSeconds = now.minusSeconds(50);
Let us now minus nanoseconds from Instant:
Instant resNanoSeconds = now.minusNanos(10000);
Example
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); } }
Output
1975-11-02T06:42:20.078Z After subtracting seconds = 1975-11-02T06:41:30.078Z After subtracting nanoseconds = 1975-11-02T06:42:20.077990Z
- Related Articles
- Java Program to get Epoch seconds from Instant
- Java Program to get Milli seconds from Instant
- Instant minus() method in Java
- Java Program to create Instant from Epoch second and millisecond
- How to get the seconds and minutes between two Instant timestamps in Java
- Java Program to create Duration from seconds
- Java Program to convert Instant to LocalDateTime
- Java Program to convert java.util.Date to Instant
- Java Program to convert this duration to the total length in nanoseconds
- Java Program to get the current value of the system timer in nanoseconds
- Java Program to display Frame after some seconds
- Display nanoseconds with Java Date and Time Conversion Character
- Python program to convert seconds into hours, minutes and seconds
- How to get (format) date and time from mill seconds in Java?
- How to measure elapsed time in nanoseconds with Java?

Advertisements