要格式化和显示日期时间,您需要使用DateTimeFormatter并将模式用作:
DateTimeFormatter dtFormat = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a z");上面的z是时区:
MMM dd yyyy hh:mm a z
现在,将以下内容用于区域:
ZonedDateTime dateTime = ZonedDateTime.now();
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class Demo {
public static void main(String[] argv) {
DateTimeFormatter dtFormat = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a z");
ZonedDateTime dateTime = ZonedDateTime.now();
String res = dateTime.format(dtFormat);
System.out.printf("Date = %s %n", res);
}
}输出结果
Date = Apr 14 2019 01:35 PM IST