Advertisement

Calendar 实现年、月、周的最后一天支持时间至23:59:59

阅读量:

1、当前日期所在月的最后一天 精确到时分秒23:59:59

复制代码
 //日期格式化

    
 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
 Date date = new Date();
    
 System.out.println(sdf.format(date));//2024-06-06 11:19:31
    
  
    
 //设置calendar
    
 Calendar calendar = Calendar.getInstance();
    
 calendar.setTime(date);
    
 calendar.set(Calendar.HOUR_OF_DAY, 23);//设置小时
    
 calendar.set(Calendar.MINUTE, 59);//设置分钟
    
 calendar.set(Calendar.SECOND, 59);//设置秒
    
 calendar.set(Calendar.MILLISECOND, 0);//设置毫秒
    
  
    
 System.out.println("------当前日期所在月的最后一天 精确到时分秒23:59:59--------")

全部评论 (0)

还没有任何评论哟~