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
热门推荐
10 送花祝福语简短十一朵
11 五一祝福语大全简短最新
12 孩子出院上班祝福语简短
13 新房落成的简短祝福语
14 领证结婚搞笑祝福语简短
15 兄弟告别的祝福语简短
16 男子成婚诗词祝福语简短
17 新年英文祝福语简短老师
18 朋友结婚致辞祝福语简短