Javatime-localdate-format
提供:Dev Guides
java.time.LocalDate.format()メソッドの例
説明
- java.time.LocalDate.format(DateTimeFormatter formatter)*メソッドは、指定されたフォーマッターを使用してこの日付をフォーマットします。
宣言
以下は* java.time.LocalDate.format(DateTimeFormatter formatter)*メソッドの宣言です。
public String format(DateTimeFormatter formatter)
パラメーター
*formatter* -使用するフォーマッタ、nullではない。
戻り値
書式設定された日付文字列、null以外
例外
*DateTimeException* -印刷中にエラーが発生した場合。
例
次の例は、java.time.LocalDate.format(DateTimeFormatter formatter)メソッドの使用方法を示しています。
package com.finddevguides;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class LocalDateDemo {
public static void main(String[] args) {
LocalDate date = LocalDate.parse("2017-02-03");
System.out.println(date);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/YYYY");
System.out.println(formatter.format(date));
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
2017-02-03
03/02/2017