指定日期判断是否节假日

最近工作需要定时器发布任务,但是定时器发布任务是指定日期,有时候涉及到节假日,这里就需要过滤掉节假日了,所以二话不说直接上代码

code=2调休    code=1正常的周六日   code=0工作日
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
import javax.net.ssl.*;
import java.io.*;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
/*
* 判断当前时间是不是工作日
* */
public  Boolean getData(){
    SimpleDateFormat dft2 = new SimpleDateFormat("yyyyMMdd");
    String newDate=dft2.format(new Date());
    String  addess = "http://api.goseek.cn/Tools/holiday?date="+newDate;
    URL url = null;
    HttpURLConnection httpConn = null;
    BufferedReader in = null;

    StringBuffer sb = new StringBuffer();
    try{
        url = new URL(addess);
        in = new BufferedReader(new InputStreamReader(url.openStream(),"utf-8") );
        String str = null;
        while((str = in.readLine()) != null) {
            sb.append( str );
        }
    } catch (Exception ex) {
    } finally{
        try{
            if(in!=null) {
                in.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    String  data =sb.toString();
    JSONObject json =  getjson(data);
    String value=json.get("data").toString();
    System.out.println(value);
    if(value.equals("0"))
        return true;
    else
        return false;
}
//json串转化为json对象
public  JSONObject getjson(String data) {
    JSONObject json = JSONObject.fromObject(data);
    return json;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章