之前有个项目的时间格式是2020/2/7
就是如果日期或者月份不到10则不显示前面的0。记录一下
public static void main(String[] args) {
final String yyyyMMddStr = "yyyy/M/d";
final String yyyyMMddStr2 = "yyyy/MM/dd";
String time = "2021/09/09";
LocalDate localDate = LocalDate.parse(time, DateTimeFormatter.ofPattern(yyyyMMddStr));
System.out.println(localDate.format(DateTimeFormatter.ofPattern(yyyyMMddStr)));
System.out.println(localDate.format(DateTimeFormatter.ofPattern(yyyyMMddStr2)));
}
image.png
网友评论