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



描述

java.time.ZonedDateTime.withSecond(int seconds) 方法返回一個已更改其秒數的此分割槽分割槽日期時間副本。

宣告

下面是 java.time.ZonedDateTime.withSecond(int seconds) 方法的宣告。

public ZonedDateTime withSecond(int seconds)

java.time.ZonedDateTime withSecond(int seconds)

引數

seconds − 要在結果中設定的秒數,範圍為 0 至 59。

返回值

以與此日期匹配的請求納秒數為基礎的分割槽分割槽日期時間,不能為空。

異常

DateTimeException − 如果一天的小時值無效。

示例

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.withSecond(30);
      System.out.println(result);  
   }
}

現場演示

2017-03-28T12:25:30.492+05:30[Asia/Calcutta]
列印頁面
廣告
© . All rights reserved.