java.time.ZonedDateTime.withFixedOffsetZone() 方法示例



描述

java.time.ZonedDateTime.withFixedOffsetZone() 方法返回此日期時間複製件,且區域 ID 設定為偏移值。

宣告

以下是 java.time.ZonedDateTime.withFixedOffsetZone() 方法的宣告。

public ZonedDateTime withFixedOffsetZone()

返回值

區域 ID 設定為偏移值的 ZonedDateTime,非空值。

示例

以下示例展示了 java.time.ZonedDateTime.withFixedOffsetZone() 方法的使用。

package com.tutorialspoint;

import java.time.ZonedDateTime;

public class ZonedDateTimeDemo {
   public static void main(String[] args) {
      
      ZonedDateTime date = ZonedDateTime.parse("2017-03-28T12:25:38.492+05:30[Asia/Calcutta]");
      ZonedDateTime result = date.withFixedOffsetZone();
      System.out.println(result);  
   }
}

讓我們編譯並執行以上程式,這將生成以下結果 −

2017-03-28T12:25:38.492+05:30
廣告