否是工作日 java 接口_java调用百度接口判断日期是否是工作日 周末还是节假日...

该博客介绍了如何使用Java编写代码,通过调用百度接口来判断输入的日期是工作日、周末还是节假日。示例代码展示了获取当前日期并发送HTTP GET请求到指定接口,解析返回的JSON结果,最终输出判断结果。
摘要由CSDN通过智能技术生成

package com.qms.utils;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Map;

public class holiday {

/**

* @param urlAll

*            :请求接口

* @param httpArg

*            :参数

* @return 返回结果

*/

public static String request( String httpArg) {

String httpUrl="http://www.easybots.cn/api/holiday.php";

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);

sbf.append("\r\n");

}

reader.close();

result = sbf.toString();

Map map=JsonUtil.toMap(result);

String res=(String)map.get(httpArg);

} catch (Exception e) {

e.printStackTrace();

}

return result;

}

public static void main(String[] args) {

//判断今天是否是工作日 周末 还是节假日

SimpleDateFormat f=new SimpleDateFormat("yyyyMMdd");

String httpArg=f.format(new Date());

System.out.println(httpArg);

String jsonResult = request(httpArg);

Map map=JsonUtil.toMap(jsonResult);

String res=(String)map.get(f.format(new Date()));

System.out.println(res);

//0 上班 1周末 2节假日

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值