Javatime-localdatetime-withsecond
提供:Dev Guides
java.time.LocalDateTime.withSecond()メソッドの例
説明
- java.time.LocalDateTime.withSecond(int seconds)*メソッドは、秒が変更されたこのLocalDateTimeのコピーを返します。
宣言
以下は、* java.time.LocalDateTime.withSecond(int seconds)*メソッドの宣言です。
public LocalDateTime withSecond(int seconds)
パラメーター
*seconds* -結果に設定する秒、0〜59。
戻り値
要求された秒を含むこの日付に基づくLocalDateTime、nullではない
例外
*DateTimeException* -秒の値が無効な場合。
例
次の例は、java.time.LocalDateTime.withSecond(int seconds)メソッドの使用法を示しています。
package com.finddevguides;
import java.time.LocalDateTime;
public class LocalDateTimeDemo {
public static void main(String[] args) {
LocalDateTime date = LocalDateTime.parse("2017-01-03T10:15:30");
LocalDateTime result = date.withSecond(40);
System.out.println(result);
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
2017-03-03T10:15:40