java.time.OffsetDateTime.toLocalDate()方法

2019-10-16 22:43:31

java.time.OffsetDateTime.toLocalDate()方法獲取此日期時間的LocalDate部分。

宣告

以下是java.time.OffsetDateTime.toLocalDate()方法的宣告。

public LocalDate toLocalDate()

返回值

此日期時間的日期部分,不為null

範例

以下範例顯示了java.time.OffsetDateTime.toLocalDate()方法的用法。

package com.yiibai;

import java.time.OffsetDateTime;

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

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

編譯並執行上面的程式,這將產生以下結果 -

2017-03-21