×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Neville Kemble
Added: Jun 5, 2022 4:12 PM
Modified: Jun 11, 2022 2:48 PM
Views: 10
Tags: date util
  1. public class DateUtil {
  2.         private static int getMaxWeekOfYear(int year) {
  3.                 java.util.Calendar calendar = java.util.Calendar.getInstance();
  4.                 calendar.set(year, java.util.Calendar.DECEMBER, 31);
  5.                 return calendar.getActualMaximum(java.util.Calendar.WEEK_OF_YEAR);
  6.         }
  7.        
  8.         public static LocalDateTime toLocalDateTime(Date date) {
  9.                 return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
  10.         }
  11.  
  12.         public static boolean sameDay(LocalDateTime thisDate, LocalDateTime thatDate) {
  13.                 return thisDate.toLocalDate().atStartOfDay().isEqual(thatDate.toLocalDate().atStartOfDay());
  14.         }
  15.        
  16.         public static boolean isEqual(LocalDateTime thisDate, LocalDateTime thatDate) {
  17.                 return thisDate.isEqual(thatDate);
  18.         }
  19.        
  20.         public static boolean isBefore(LocalDateTime thisDate, LocalDateTime thatDate) {
  21.                 return thisDate.isBefore(thatDate);
  22.         }
  23.        
  24.         public static boolean isAfter(LocalDateTime thisDate, LocalDateTime thatDate) {
  25.                 return thisDate.isAfter(thatDate);
  26.         }
  27. }