java判断日期为双休日

编程入门 行业动态 更新时间:2024-10-06 08:34:55

java判断日期为<a href=https://www.elefans.com/category/jswz/34/1768209.html style=双休日"/>

java判断日期为双休日

一.工具类

package com.tecnonmon.utils;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.HttpURLConnection;

import java.URL;

/**

* @author scy

* @date 2020/7/30 8:54

* 判断当前是否为节假日: 0 上班 1周末 2节假日

*/

public class HolidayUtil {

/**

* 判断当前是否为节假日: 0 上班 1周末 2节假日

* @param httpArg :参数

* @return 返回结果

*/

public static String request(String httpArg) {

String httpUrl = "/";

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 static void main(String[] args) {

// 处理节假日

SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");

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

String jsonResult = HolidayUtil.request(httpArg);

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

if ("0".equals(jsonResult)) {

System.out.println("0上班");

}

if ("1".equals(jsonResult)) {

System.out.println("1周末");

}

if ("2".equals(jsonResult)) {

System.out.println("2节假日");

}

}

}

更多推荐

java判断日期为双休日

本文发布于:2024-02-28 04:44:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1768127.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双休日   日期   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!