Java 程序将日期格式化为 2019 年 4 月 19 日,下午 1:27
要设置格式并显示日期时间,你需要使用 DateTimeFormatter。格式风格为 MEDIUM 和 SHORT
DateTimeFormatter formatter = DateTimeFormatter .ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT);
显示格式化的日期
formatter.format(LocalDateTime.now()
示例
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
public class Demo {
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter .ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT);
System.out.println("Formatted Date = "+formatter.format(LocalDateTime.now()));
}
}输出
Formatted Date = Apr 19, 2019, 1:27 PM
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP