如何将Java LocalDateTime格式化为ISO_DATE_TIME格式
首先,设置日期:
LocalDateTime dateTime = LocalDateTime.of(2019, Month.JULY, 9, 10, 20);
现在,将日期时间格式化为ISO_DATE_TIME格式:
String str = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);
示例
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
public class Demo {
public static void main(String[] args) {
LocalDateTime dateTime = LocalDateTime.of(2019, Month.JULY, 9, 10, 20);
System.out.println("DateTime = "+dateTime);
String str = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);
System.out.println("Formatted date = "+str);
}
}输出结果
DateTime = 2019-07-09T10:20 Formatted date = 2019-07-09T10:20:00
热门推荐
10 猪年元旦祝福语简短创意
11 牙医生日祝福语简短
12 亲戚送行祝福语简短精辟
13 结婚祝福语亲姐姐简短
14 新人结婚父母祝福语简短
15 收围巾的祝福语简短
16 生日祝福语古语简短创意
17 简短正能量生日祝福语
18 生日祝福语简短明了 同事