java.time.OffsetDateTime.toEpochSecond()方法

java.time.OffsetDateTime.toEpochSecond()方法将此日期时间转换为1970-01-01T00:00:00Z的纪元的秒数。

声明

以下是java.time.OffsetDateTime.toEpochSecond()方法的声明。

public long toEpochSecond()

返回值

1970-01-01T00:00:00Z时代以来的秒数。

以下示例显示了java.time.OffsetDateTime.toEpochSecond()方法的用法。

package com.zaixian;

import java.time.OffsetDateTime;

public class OffsetDateTimeDemo {
   public static void main(String[] args) {

      OffsetDateTime date = OffsetDateTime.now();
      System.out.println(date.toEpochSecond());  
   }
}

编译并运行上面的程序,这将产生以下结果 -

1490085824

上一篇: java.time.OffsetDateTime类 下一篇: java.time.OffsetTime类