| | |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) throws ParseException { |
| | | //Date d1 = YYYY_MM_DD_HH_MM_SS.parse("2023-01-22 14:12:22"); |
| | | //Date d2 = YYYY_MM_DD_HH_MM_SS.parse("2023-08-24 16:45:22"); |
| | | //Map<String, List<Date>> monthListDesc = getQueryTimeForSubTablesByMonthDesc(d1, d2); |
| | | // |
| | | //Set<Map.Entry<String, List<Date>>> entries = monthListDesc.entrySet(); |
| | | //for (Map.Entry<String, List<Date>> entry : entries) { |
| | | // System.out.println(entry); |
| | | //} |
| | | //Map<String,String> map = new HashMap<>(); |
| | | //map.put("2022_01",""); |
| | | //map.put("2022_02",""); |
| | | //map.put("2022_10",""); |
| | | //map.put("2022_12",""); |
| | | //map.put("2021_03",""); |
| | | //map.put("2023_01",""); |
| | | //map.put("2023_05",""); |
| | | //map.put("2021_10",""); |
| | | //Set<String> keySet = map.keySet(); |
| | | //List<String> keySetDesc = keySet.stream().sorted(Comparator.comparing(String::hashCode).reversed()).collect(Collectors.toList()); |
| | | String t1 = "2024-01-25 12:22:29"; |
| | | String t2 = "2024-01-25 12:32:24"; |
| | | String t3 = "2024-01-25 12:42:26"; |
| | | Date maxTime = getMaxTime(t1, t2, t3); |
| | | System.out.println(maxTime.toString()); |
| | | |
| | | |
| | | /** |
| | | * 获取本年的开始时间 |
| | | */ |
| | | public static LocalDateTime getStartOfYear() { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | return now.with(TemporalAdjusters.firstDayOfYear()).with(LocalDateTime.MIN.toLocalTime()); |
| | | } |
| | | |
| | | /** |
| | | * 获取本季度的开始时间 |
| | | */ |
| | | public static LocalDateTime getStartOfQuarter() { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | int currentMonthValue = now.getMonthValue(); |
| | | // 计算当前季度的第一个月 |
| | | int quarterStartMonth = 3 * ((currentMonthValue - 1) / 3) + 1; |
| | | return LocalDate.of(now.getYear(), quarterStartMonth, 1).atStartOfDay(); |
| | | } |
| | | |
| | | /** |
| | | * 获取本月的开始时间 |
| | | */ |
| | | public static LocalDateTime getStartOfMonth() { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | return now.with(TemporalAdjusters.firstDayOfMonth()).with(LocalDateTime.MIN.toLocalTime()); |
| | | } |
| | | |
| | | /** |
| | | * Date 转 LocalDateTime 工具方法 |
| | | */ |
| | | public static LocalDateTime convertToLocalDateTime(java.util.Date date) { |
| | | return date.toInstant() |
| | | .atZone(ZoneId.systemDefault()) |
| | | .toLocalDateTime(); |
| | | } |
| | | } |