Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
Advertisements