Java8新特性:时间格式化与时区的处理
作者:互联网
时间格式化:
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);
}
}
标签:格式化,System,LocalDateTime,println,java,时区,now,Java8,out 来源: https://www.cnblogs.com/wyw123456/p/15787864.html