java.time.OffsetDateTime.toEpochSecond() Method Example



Description

The java.time.OffsetDateTime.toEpochSecond() method converts this date-time to the number of seconds from the epoch of 1970-01-01T00:00:00Z.

Declaration

Following is the declaration for java.time.OffsetDateTime.toEpochSecond() method.

public long toEpochSecond()

Return Value

the number of seconds from the epoch of 1970-01-01T00:00:00Z.

Example

The following example shows the usage of java.time.OffsetDateTime.toEpochSecond() method.

package com.tutorialspoint;

import java.time.OffsetDateTime;

public class OffsetDateTimeDemo {
   public static void main(String[] args) {
 
      OffsetDateTime date = OffsetDateTime.now();
      System.out.println(date.toEpochSecond());  
   }
}

Let us compile and run the above program, this will produce the following result −

1490085824
Advertisements