你好,這個(gè)功能一般是使用一個(gè)專門的數(shù)據(jù)庫表把一年的節(jié)假日都存進(jìn)去來判斷的。國家每年都會提前發(fā)布一年的節(jié)假日,然后我們再導(dǎo)入到數(shù)據(jù)庫。而特殊的做法應(yīng)該可以接入百度之類的接口。希望能幫到你。
我們提供的服務(wù)有:成都做網(wǎng)站、成都網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、吳川ssl等。為1000+企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的吳川網(wǎng)站制作公司
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
* :參數(shù)
* @return 返回結(jié)果
*/
public static String request( String httpArg) {
String httpUrl="ay.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();
MapString,Object map=JsonUtil.toMap(result);
String res=(String)map.get(httpArg);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
//判斷今天是否是工作日 周末 還是節(jié)假日
SimpleDateFormat f=new SimpleDateFormat("yyyyMMdd");
String httpArg=f.format(new Date());
System.out.println(httpArg);
String jsonResult = request(httpArg);
MapString,Object map=JsonUtil.toMap(jsonResult);
String res=(String)map.get(f.format(new Date()));
System.out.println(res);
//0 上班 1周末 2節(jié)假日
}
}
沒有此方法,只能判斷是星期幾。因?yàn)橹袊墓?jié)假日是農(nóng)歷!而java不是中國人搞出來的!。
public?static?boolean?isWeekend(Date?date)?{
Calendar?cal?=?Calendar.getInstance();
cal.setTime(date);
int?result?=?cal.get(Calendar.WEEK_OF_MONTH);
if?(result?==?Calendar.SATURDAY?||?result?==?Calendar.SUNDAY)?{
return?true;
}
return?false;
}
這段代碼只是判斷是不是周末,節(jié)假日的話只能通過某些數(shù)據(jù)配置來判斷了。節(jié)假日是沒法計(jì)算的。
當(dāng)前標(biāo)題:Java代碼辨別節(jié)假日 java判斷日期周末節(jié)假日
標(biāo)題網(wǎng)址:http://aaarwkj.com/article30/hhhspo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、全網(wǎng)營銷推廣、電子商務(wù)、靜態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)