如何将Java日期显示为'12 / 04/2019'
要格式化和显示日期(例如日/月/年),您需要设置模式:
dd/MM/yyyy
首先,设置一个LocalDate:
LocalDate localDate = LocalDate.now();
现在格式化并显示日期为'12/04/2019':
localDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))示例
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Demo {
public static void main(String[] args) {
LocalDate date = LocalDate.now();
System.out.println("Date = "+date);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
System.out.println("Formatted Date = "+date.format(formatter));
}
}输出结果
Date = 2019-04-12 Formatted Date = 12/04/2019
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短