java.time.LocalDateTime.format(DateTimeFormatter formatter)方法使用指定的格式化程序格式化此日期时间。
声明
以下是java.time.LocalDateTime.format(DateTimeFormatter formatter)方法的声明。
public String format(DateTimeFormatter formatter)
参数formatter - 要使用的格式化程序,而不是null。
返回值
格式化的日期字符串,不为null。
异常
DateTimeException - 如果在打印期间发生错误。
示例
以下示例显示了java.time.LocalDateTime.format(DateTimeFormatter formatter)方法的用法。
package com.yiibai;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class LocalDateTimeDemo {
public static void main(String[] args) {
LocalDateTime date = LocalDateTime.parse("2017-02-03T12:30:30");
System.out.println(date);
DateTimeFormatter formatter = DateTimeFormatter.ISO_TIME;
System.out.println(formatter.format(date));
}
}
编译并运行上面的程序,这将产生以下结果 -
2017-02-03T12:30:30
12:30:30
¥ 我要打赏
纠错/补充
收藏
加QQ群啦,易百教程官方技术学习群
注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。