2026-03-03 00:16:12 +08:00
|
|
|
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");
|
2026-03-03 09:51:26 +08:00
|
|
|
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月");
|
|
|
|
|
|
2026-03-03 00:16:12 +08:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 09:51:26 +08:00
|
|
|
public static String getCurrentYearMonthCN() {
|
|
|
|
|
LocalDate currentDate = LocalDate.now();
|
|
|
|
|
return currentDate.format(YEAR_MONTH_CN_FORMATTER);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 00:16:12 +08:00
|
|
|
public static String getYear(LocalDate date) {
|
|
|
|
|
return date.format(YEAR_FORMATTER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getMonth(LocalDate date) {
|
|
|
|
|
return date.format(MONTH_FORMATTER);
|
|
|
|
|
}
|
|
|
|
|
}
|