- 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 get the seconds since the beginning of the Java epoch
To get the seconds since the beginning of epochs, you need to use Instant. The method here used is ofEpochSecond() method. The epoch is the number of seconds that have elapsed since 00::00:00 Thursday, 1 January 1970.
Get the seconds with ChronoUnit.SECONDS −
long seconds = Instant.ofEpochSecond(0L).until(Instant.now(), ChronoUnit.SECONDS);
Example
import java.time.Instant; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { long seconds = Instant.ofEpochSecond(0L).until(Instant.now(), ChronoUnit.SECONDS); System.out.println("Seconds since the beginning of the Java epoch = "+seconds); } }
Output
Seconds since the beginning of the Java epoch = 1555053202
- Related Articles
- Java Program to get Epoch seconds from Instant
- Display seconds since the epoch with Java Date and Time Conversion Character
- How can I get seconds since epoch in JavaScript?
- Displaymilliseconds since the epoch with Java Date and Time Conversion Character
- Java Program to get the beginning and end date of the week
- How to get time in milliseconds since the Unix epoch in JavaScript?
- Java Program to check the beginning of a string
- How can I get days since epoch in JavaScript?
- Java Program to get the difference between two time zones by seconds
- Java Program to get Milli seconds from Instant
- How can I get time and date since epoch in JavaScript?
- Java Program to get the reverse of the NavigableSet
- Java Program to Get the Size of the Collection
- Java Program to remove whitespace from the beginning and end of a string
- How to match the beginning of the input using Java RegEx?

Advertisements