时间格式化:
package com;
import java.time.*;
import java.time.format.DateTimeFormatter;
public class Main1 {
public static void main(String[] args){
LocalDateTime now = LocalDateTime.now();
String isoDateTime = now.format(DateTimeFormatter.ISO_DATE_TIME);
System.out.println("isoDateTime = " + isoDateTime);
String isoDate = now.format(DateTimeFormatter.ISO_DATE);
System.out.println("isoDate = " + isoDate);
String my = now.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss"));
System.out.println("my = " + my);
}
}
======================
时区:
package com;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class Main1 {
public static void main(String[] args){
LocalDateTime now = LocalDateTime.now();
LocalDateTime now1 = LocalDateTime.now(ZoneId.of("Europe/Moscow"));
ZonedDateTime zonedDateTime = now.atZone(ZoneId.of("Asia/Shanghai"));
System.out.println("now = " + now);
System.out.println("now1 = " + now1);
System.out.println("zonedDateTime = " + zonedDateTime);
}
}