栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java 当前日期判断节假日

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java 当前日期判断节假日

Java关于日期处理
  1. 获取今天日期(today)

    	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	Date date = new Date();
    	String today = dateFormat.format(date);
    
  2. 获取明天日期(tomorrow)

    	Date today = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        String yesterday = simpleDateFormat.format(today);//获取明天日期
    
  3. 获取昨天日期(yesterday)

    	Date today = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        String yesterday = simpleDateFormat.format(today);//获取昨天日期
    
  4. 判断是否是工作日

    public static String request(String httpArg) {
        String httpUrl = "http://tool.bitefu.net/jiari/";
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();
        httpUrl = httpUrl + "?d=" + httpArg;
        try {
            URL url = new URL(httpUrl);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            InputStream is = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            String strRead = null;
            while ((strRead = reader.readLine()) != null) {
                sbf.append(strRead);
    
            }
            reader.close();
            result = sbf.toString();
        } catch (Exception e) {
            e.printStackTrace();
    
        }
    
        return result;
    
    }
    
    public String dateType(String httpArg){
        String jsonResult = request(httpArg);
        //String jsonResult = HolidayUtil.request("20220715");
        // 0 上班 1周末 2节假日
        String type = null;
       switch (jsonResult){
           case "0":
               type = "工作日";
               break;
           case "1":
               type = "周末";
               break;
           case "2" :
               type = "节假日";
               break;
    
       }
       return type;
    }
    
  5. 判断是否是节假日

    public static String request(String httpArg) {
        String httpUrl = "http://tool.bitefu.net/jiari/";
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();
        httpUrl = httpUrl + "?d=" + httpArg;
        try {
            URL url = new URL(httpUrl);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            InputStream is = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            String strRead = null;
            while ((strRead = reader.readLine()) != null) {
                sbf.append(strRead);
    
            }
            reader.close();
            result = sbf.toString();
        } catch (Exception e) {
            e.printStackTrace();
    
        }
    
        return result;
    
    }
    
    public String dateType(String httpArg){
        String jsonResult = request(httpArg);
        //String jsonResult = HolidayUtil.request("20220715");
        // 0 上班 1周末 2节假日
        String type = null;
       switch (jsonResult){
           case "0":
               type = "工作日";
               break;
           case "1":
               type = "周末";
               break;
           case "2" :
               type = "节假日";
               break;
    
       }
       return type;
    }
    
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1040195.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号