- 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
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
Advertisements