- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
What is the use of the toEpochSecond() method in Java 9?
In Java 9, the LocalDate class provides the toEpochSecond() method to convert local date into epoch seconds. The toEpochSecond() method converts the LocalDate to a number of seconds since the epoch 1970-01-01T00:00:00Z. The LocalDate can be combined with a given time and zone offset to calculate seconds starting from 1970-01-01T00:00:00Z.
Syntax
public long toEpochSecond(LocalTime time, ZoneOffset offset)
Example
import java.time.LocalDate; import java.time.LocalTime; import java.time.ZoneOffset; public class ToEpochSecondMethodTest { public static void main(String args[]) { LocalDate date = LocalDate.now(); LocalTime time = LocalTime.now(); System.out.println("LocalDate toEpochSecond : " + date.toEpochSecond(time, ZoneOffset.of("Z"))); System.out.println("LocalTime toEpochSecond : " + time.toEpochSecond(date, ZoneOffset.of("Z"))); } }
Output
LocalDate toEpochSecond : 1583496984 LocalTime toEpochSecond : 1583496984
- Related Articles
- What is the use of the Optional.stream() method in Java 9?\n
- What is the use of the Cleaner class in Java 9?
- What is the use of the jdeprscan tool in Java 9?
- What is the use of underscore keyword in Java 9?
- What is the use of setBounds() method in Java?
- What is the use of Thread.sleep() method in Java?
- When to use the readAllBytes() method of InputStream in Java 9?
- When to use the readNBytes() method of InputStream in Java 9?
- When to use the delayedExecutor() method of CompletableFuture in Java 9?
- What is the use of the Tab key in JShell in Java 9?
- What is the purpose of using Optional.ifPresentOrElse() method in Java 9?
- When to use the ofNullable() method of Stream in Java 9?\n
- What is the use of a multi-version compatible jar in Java 9?
- How to use the collect() method in Stream API in Java 9?
- What is the use of the "requires" clause in a module-info file in Java 9?

Advertisements