java.time.LocalTime.format(DateTimeFormatter formatter)
方法使用指定的格式化程序进行格式化。
声明
以下是java.time.LocalTime.format(DateTimeFormatter formatter)
方法的声明。
public String format(DateTimeFormatter formatter)
参数
Formatter
- 要使用的格式化程序,而不是null
。
返回值
格式化的日期字符串,不为null
。
异常
DateTimeException
- 如果在打印期间发生错误。
示例
以下示例显示了java.time.LocalTime.format(DateTimeFormatter formatter)
方法的用法。
package com.yiibai;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class LocalTimeDemo {
public static void main(String[] args) {
LocalTime time = LocalTime.parse("12:30:30");
System.out.println(time);
DateTimeFormatter formatter = DateTimeFormatter.ISO_TIME;
System.out.println(formatter.format(time));
}
}
编译并运行上面的程序,这将产生以下结果 -
12:30:30
12:30:30