如何将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 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短