zoukankan      html  css  js  c++  java
  • Java判断指定日期是否为工作日

    Java判断指定日期是否为工作日

    转自:https://www.jianshu.com/p/966659492f2f

    转:https://www.jianshu.com/p/05ccb5783f65
    转:https://www.jianshu.com/p/99931a7a4f0d
    获取指定日期的节假日信息: http://api.goseek.cn/

    package com.juqitech.zb.common.util;
    
    import net.sf.json.JSONObject;
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.text.SimpleDateFormat;
    
    
    /**
     * 调用API接口判断日期是否是工作日 周末还是节假日
     * 工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2
     */
    public class HolidayUtil {
    
        public static int request( String httpArg) {
            String httpUrl = "http://api.goseek.cn/Tools/holiday";
            BufferedReader reader = null;
            String result = null;
            StringBuffer sbf = new StringBuffer();
            httpUrl = httpUrl + "?date=" + httpArg;
    
            int d=0;//工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2
    
            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);
                    sbf.append("
    ");
                }
                reader.close();
                result = sbf.toString();
                JSONObject ob= JSONObject.fromObject(result);
                if(ob!=null){
                    d=Integer.parseInt(ob.getString("data"));
                }
    
    
    
            } catch (Exception e) {
                e.printStackTrace();
            }
            return d;
        }
    
        public static void main(String[] args) {
            //判断今天是否是工作日 周末 还是节假日
    
            SimpleDateFormat f=new SimpleDateFormat("yyyyMMdd");
    
            String httpArg="20190216";//f.format(new Date());
            System.out.println(httpArg);
            int n = request(httpArg);
            System.out.println(n);
            //工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2
    
        }
    }
    

     

     

  • 相关阅读:
    golang linux安装
    vscode 插件
    windows访问eks pods
    go mod包管理
    beego创建项目
    Atcoder ARC-125
    AtCoder AGC003 简要题解
    Python 字符串转成变量名
    13_Go基础(binary)
    12_Go基础(iota)
  • 原文地址:https://www.cnblogs.com/personsiglewine/p/11460084.html
Copyright © 2011-2022 走看看