Java 程序将日期格式化为 2019 年 4 月 14 日 下午 01:35 IST
要格式化和显示日期时间,你需要使用 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
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP