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
    
        }
    }
    

     

     

  • 相关阅读:
    jQuery中$.proxy()的原理和使用
    JS中各种宽度、高度、位置、距离总结
    js中得call()方法和apply()方法的用法
    google浏览器翻译失败解决方案
    js区分移动设备与PC
    知识积累
    Django
    leetcode 27.Remove Element
    leetcode 28. Implement strStr()
    21. Merge Two Sorted Lists
  • 原文地址:https://www.cnblogs.com/personsiglewine/p/11460084.html
Copyright © 2011-2022 走看看