• JAVA获取一个月有多少天,以及判断当前天为周几


    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;
    
    /***
     * 
     * @author zhanchaohan
     *
     */
    public class Calender {
        static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
        private static void getMonthLastDay(Date date) throws ParseException {
            GregorianCalendar cal = new GregorianCalendar();
    
            cal.setTime(date);
            System.out.println(cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        }
    
        private static void getDayOfWeek(Date date) {
            GregorianCalendar cal = new GregorianCalendar();
    
            cal.setTime(date);
            int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
            char[] weekChar = new char[] { '日', '一', '二', '三', '四', '五', '六' };
            System.out.println(weekChar[dayOfWeek - 1]);
        }
    
        public static void main(String[] args) throws ParseException {
    //        getMonthLastDay(sdf.parse("2021-6-1 00:00:00"));
    //        getMonthLastDay(sdf.parse("2021-7-1 00:00:00"));
    //        getMonthLastDay(sdf.parse("2021-8-1 00:00:00"));
    //        getMonthLastDay(sdf.parse("2021-9-1 00:00:00"));
    
            getDayOfWeek(sdf.parse("2021-2-1 00:00:00"));
            getDayOfWeek(sdf.parse("2021-2-2 00:00:00"));
            getDayOfWeek(sdf.parse("2021-2-3 00:00:00"));
            getDayOfWeek(sdf.parse("2021-2-4 00:00:00"));
            getDayOfWeek(sdf.parse("2021-2-5 00:00:00"));
            getDayOfWeek(sdf.parse("2021-2-6 00:00:00"));
            getDayOfWeek(sdf.parse("2021-2-7 00:00:00"));
        }
    }
  • 相关阅读:
    Nginx工作原理
    Redis核心原理
    Nginx介绍
    资源平衡与资源平滑
    HDFS(Hadoop Distributed File System)的组件架构概述
    HBase的应用场景及特点
    HBase详解
    Nginx被动健康检查和主动健康检查
    lsof 详解
    Dockerfile文件详解
  • 原文地址:https://www.cnblogs.com/zhanchaohan/p/14957472.html
Copyright © 2020-2023  润新知