package com.mini.mybigscreen.utils; import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class DateUtils { private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("MM"); private static final DateTimeFormatter YEAR_FORMATTER = DateTimeFormatter.ofPattern("yyyy"); private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd"); private static final DateTimeFormatter YEAR_MONTH_CN_FORMATTER = DateTimeFormatter.ofPattern("yyyy年MM月"); private static final DateTimeFormatter SHORT_YEAR_MONTH_CN_FORMATTER = DateTimeFormatter.ofPattern("yy年MM月"); public static String dsValue() { LocalDate currentDate = LocalDate.now(); return currentDate.format(DATE_FORMATTER); } public static String dsValueDaysAgo(long days) { LocalDate targetDate = LocalDate.now().minusDays(days); return targetDate.format(DATE_FORMATTER); } public static String getCurrentYear() { LocalDate currentDate = LocalDate.now(); return currentDate.format(YEAR_FORMATTER); } public static String getCurrentMonth() { LocalDate currentDate = LocalDate.now(); return currentDate.format(MONTH_FORMATTER); } public static String getCurrentYearMonthCN() { LocalDate currentDate = LocalDate.now(); return currentDate.format(YEAR_MONTH_CN_FORMATTER); } public static String getCurrentShortYearMonthCN() { LocalDate currentDate = LocalDate.now(); return currentDate.format(SHORT_YEAR_MONTH_CN_FORMATTER); } public static String getYear(LocalDate date) { return date.format(YEAR_FORMATTER); } public static String getMonth(LocalDate date) { return date.format(MONTH_FORMATTER); } }