Java 8及以上版本中可以使用以下代码获取当前月份并格式化为'yyyy-MM':

LocalDate now = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
String formattedDate = now.format(formatter);
System.out.println(formattedDate);

输出结果为当前年月的字符串,例如:2021-08。

LocalDate获取当前月份格式化为yyyy-MM

原文地址: https://www.cveoy.top/t/topic/f2WL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录