string转localdate,只有年月要怎末转, 用DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");,转换失败,请教一下大佬要怎末操作才能实现 报错:"DateTimeParseException: Text '2021-03' could not be parsed at index 7",
可以曲线救国,在最后拼接第几天就可以了,然后用的时候忽略天这个属性就行,你想直接这么用是不行的
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate parse = LocalDate.parse("2021-08"+"-01", fmt);
LocalDate 使用的是ISO-8601 的日历系统,格式上都要求 年月日,只能补一个date了,参考楼上的实现。
或者
使用SimpleDateFormat 转成Date类型,这种方式可以只传年和月两个参数就可以转换。