java 국가 법정 공휴일 과 휴일 판단 도구 류
4681 단어 자바
package com.date.dateutil;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* @author qyw
* @description
* @date Created in 21:01 2019/1/31
**/
public class ChineseCalendarUtils {
//
// 。 , 12 ,
// todo db list,
private List lawHolidays = Arrays.asList("2017-12-30", "2017-12-31",
"2018-01-01", "2018-02-15", "2018-02-16", "2018-02-17", "2018-02-18",
"2018-02-19", "2018-02-20", "2018-02-21", "2018-04-05", "2018-04-06",
"2018-04-07", "2018-04-29", "2018-04-30", "2018-05-01", "2018-06-16",
"2018-06-17", "2018-06-18", "2018-09-22", "2018-09-23", "2018-09-24",
"2018-10-01", "2018-10-02", "2018-10-03", "2018-10-04", "2018-10-05",
"2018-10-06", "2018-10-07");
//
// todo db list,
private List extraWorkdays = Arrays.asList("2018-02-11", "2018-02-24",
"2018-04-08", "2018-04-28", "2018-09-29", "2018-09-30");
/**
* @author qyw
* @description
* @date Created in 21:03 2019/1/31
**/
public boolean isLawHoliday(String calendar) throws Exception {
ChineseCalendarUtils.isValidDate(calendar);
if (lawHolidays.contains(calendar)) {
return true;
}
return false;
}
/**
* @author qyw
* @description
* @date Created in 21:03 2019/1/31
**/
public boolean isWeekends(String calendar) throws Exception {
ChineseCalendarUtils.isValidDate(calendar);
// Calendar
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(calendar);
Calendar ca = Calendar.getInstance();
ca.setTime(date);
if (ca.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
|| ca.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
return true;
}
return false;
}
/**
* @author qyw
* @description
* @date Created in 21:06 2019/1/31
**/
public boolean isExtraWorkday(String calendar) throws Exception {
ChineseCalendarUtils.isValidDate(calendar);
if (extraWorkdays.contains(calendar)) {
return true;
}
return false;
}
/**
* @author qyw
* @description ( )
* @date Created in 21:06 2019/1/31
**/
public boolean isHoliday(String calendar) throws Exception {
ChineseCalendarUtils.isValidDate(calendar);
//
if (this.isLawHoliday(calendar)) {
return true;
}
//
if (!this.isWeekends(calendar)) {
return false;
}
//
if (this.isExtraWorkday(calendar)) {
return false;
}
return true;
}
/**
* @author qyw
* @description , ,2007/02/30 false
* @date Created in 21:06 2019/1/31
**/
private static boolean isValidDate(String str) {
boolean convertSuccess = true;
// / / , yyyy-MM-dd ;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
// lenient false.
// SimpleDateFormat , 2007/02/29 , 2007/03/01
format.setLenient(false);
format.parse(str);
} catch (ParseException e) {
convertSuccess = false;
}
return convertSuccess;
}
public static void main(String[] args) throws Exception {
String calendar = "2018-01-32";
ChineseCalendarUtils cc = new ChineseCalendarUtils();
System.out.println(" calendar :"+ChineseCalendarUtils.isValidDate(calendar));
System.out.println(" :" + cc.isLawHoliday(calendar));
System.out.println(" :" + cc.isWeekends(calendar));
System.out.println(" :" + cc.isExtraWorkday(calendar));
System.out.println(" :" + cc.isHoliday(calendar));
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.