I need information of international holiday for a reminder to greet people ,so I worked hard on searching free API on Google.Here showed what I choose at last.
Website
http://timor.tech/api/holiday/ https://date.nager.at/swagger/index.htmlAPI format
#距离今天最近的一个放假安排 https://timor.tech/api/holiday/tts #获取指定日期的节假日信息 eg:$date=2020-02-23 https://timor.tech/api/holiday/info/$date #Return the upcoming public holidays for the next 7 days https://date.nager.at/api/v3/NextPublicHolidaysWorldwideJson Entities Class
//https://timor.tech/api/holiday/tts 距离今天最近的一个放假安排
@Data
public class FestivalReminderDTO {
public int code;
public String tts;
}
//https://timor.tech/api/holiday/info/$date 获取指定日期的节假日信息 eg:$date=2020-02-23
@Data
public class DateStatusDTO {
public Integer code;
public Type type;
public Holiday holiday;
}
@Data
public class Type {
public Integer type;
public String name;
public Integer week;
}
@Data
public class Holiday {
public boolean holiday;
public String name;
public Integer wage;
public String date;
public Integer rest;
}
//https://date.nager.at/api/v3/NextPublicHolidaysWorldwide Return the upcoming public holidays for the next 7 days
@Data
public class HolidayDTO {
private String date;
private String localName;
private String name;
private String countryCode;
private boolean fixed;
private boolean global;
private ArrayList counties;
private Object launchYear;
private ArrayList types;
}
Code Reference
//https://timor.tech/api/holiday/tts 距离今天最近的一个放假安排
public static FestivalReminderDTO getLatestFestivalObj() throws IOException {
String response1 = OU.getMethod("https://timor.tech/api/holiday/tts");
return JSON.parseObject(response1, FestivalReminderDTO.class);
}
public static String getLatestFestival() {
try {
FestivalReminderDTO latestFestivalObj = getLatestFestivalObj();
return latestFestivalObj.getTts();
} catch (IOException e) {
return "";
}
}
//https://timor.tech/api/holiday/info/$date 获取指定日期的节假日信息 eg:$date=2020-02-23
public static DateStatusDTO getDateObj(String yyyyMMdd) {
// OkHtppUtil ou1 = new OkHtppUtil();
//目前的日期
// String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis());
//请求时间
// String response1 = ou2.getMethod("https://timor.tech/api/holiday/tts");
// FestivalReminderDTO festivalReminderDTO = JSON.parseObject(response1, FestivalReminderDTO.class);
//请求今天时间
try {
String url = "https://timor.tech/api/holiday/info/" + yyyyMMdd;
String response1 = OU.getMethod(url);
return JSON.parseObject(response1, DateStatusDTO.class);
} catch (IOException e) {
return null;
}
}
//https://date.nager.at/api/v3/NextPublicHolidaysWorldwide Return the upcoming public holidays for the next 7 days
public static List getPublicHolidayObj() throws IOException {
String url = "https://date.nager.at/api/v3/NextPublicHolidaysWorldwide";
String holiday = OU.getMethod(url);
List holidayDTOS =JSONArray.parseArray(holiday,HolidayDTO.class);
return holidayDTOS;
}
public static String getNextPublicHolidaysWorldwide() {
try {
List holidayDTOS = getPublicHolidayObj();
String content;
if (Objects.isNull(holidayDTOS)) {
return "There are some mistakes during collecting public holiday worldwide,pls ask KK for help!————404";
}
content="以下是近7天内有公共节日的国家/地区,可对该地区正接洽的客人进行节日问候以增进关系:
——————————————————————
";
for (HolidayDTO holidayDTO : holidayDTOS) {
String localName = holidayDTO.getLocalName();
String publicHolidayName = holidayDTO.getName();
String date = holidayDTO.getDate();
String countryCode = holidayDTO.getCountryCode();
String countryName = CountryCode.getByCode(countryCode).getName();
Currency currency = CountryCode.getByCode(countryCode).getCurrency();
content+="日期:"+date+" 国家/地区:"+countryName+" 国际编码:"+countryCode+" 币种:"+currency+"
节日名称:"+publicHolidayName+" 当地名称:"+localName+"
————————————————————————————
";
}
return content;
} catch (IOException e) {
return "There are some mistakes during collecting public holiday worldwide,pls ask KK for help!————403";
}
}
Other url for reference
https://www.abstractapi.com/holidays-api#pricing https://holidays.abstractapi.com/v1/ ? api_key = YOUR_UNIQUE_API_KEY & country = SG
https://github.com/commenthol/date-holidays#usage https://commenthol.github.io/date-holidays/
https://github.com/nager/Nager.Date https://date.nager.at/ Swagger: https://date.nager.at/swagger/index.html API: https://date.nager.at/api/v3/NextPublicHolidaysWorldwide
https://github.com/TakahikoKawasaki https://github.com/TakahikoKawasaki/CountryCode https://github.com/TakahikoKawasaki/nv-i18n https://github.com/TakahikoKawasaki/nv-i18nFinallyExample: CountryCode cc = CountryCode.getByCode("JP"); System.out.println("Country name = " + cc.getName()); // "Japan" System.out.println("ISO 3166-1 alpha-2 code = " + cc.getAlpha2()); // "JP" System.out.println("ISO 3166-1 alpha-3 code = " + cc.getAlpha3()); // "JPN" System.out.println("ISO 3166-1 numeric code = " + cc.getNumeric()); // 392 com.neovisionaries nv-i18n1.29
It is no exaggeration to say that it’s easy to use. There are many other APIs on Google, hope I could use some of them in the future if possible.



