java.time.OffsetDateTime.toZonedDateTime() 方法示例



描述

java.time.OffsetDateTime.toZonedDateTime() 方法使用偏移作為時區 ID 將此日期時間轉換為 ZonedDateTime。

宣告

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

public ZonedDateTime toZonedDateTime()

返回值

表示時間和偏移的 OffsetTime,非空。

示例

下面的示例展示了 java.time.OffsetDateTime.toZonedDateTime() 方法的使用。

package com.tutorialspoint;

import java.time.OffsetDateTime;

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

讓我們編譯並執行上面的程式,它將產生以下結果 −

2017-03-21T14:35:55.111+05:30
廣告
© . All rights reserved.