获取指定日期的节假日信息:junit-vintage-engine

获取指定日期的节假日信息
相关pom依赖:

 <dependencies>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.46</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
  </dependencies>

HolidayTest:

package com.example.testdemo;

import com.alibaba.fastjson.JSONObject;
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.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * @Title: HolidayTest
 * @Description: 验证日期是否为节假日或者周末
 * @Auther: 
 * @Date: 2020/3/14 14:43
 *
 */
public class HolidayTest {
   

    /**
     *
        获取指定日期的节假日信息
        接口地址:http://timor.tech/api/holiday/info/$date
         @params $date: 指定日期的字符串,格式 ‘2018-02-23’。可以省略,则默认服务器的当前时间。
         @return json: 如果不是节假日,holiday字段为null。
     {
         "code": 0,                         // 0服务正常。-1服务出错
         "type": {
                 "type": enum(0, 1, 2, 3), // 节假日类型,分别表示 工作日、周末、节日、调休。
                 "name": "周六",         // 节假日类型中文名,可能值为 周一 至 周日、假期的名字、某某调休。
                 "week": enum(1 - 7)    // 一周中的第几天。值为 1 - 7,分别表示 周一 至 周日。
                 },
         "holiday": {
                 "holiday": false,     // true表示是节假日,false表示是调休
                 "name": "国庆前调休",  // 节假日的中文名。如果是调休,则是调休的中文名,例如'国庆前调休'
                 "wage": 1,            // 薪资倍数,1表示是1倍工资
                 "after": false,       // 只在调休下有该字段。true表示放完假后调休,false表示先调休再放假
                 "target": '国庆节'     // 只在调休下有该字段。表示调休的节假日
                    }
     }
     */
    public static void main(String[] args) {
   
    	//获取当前日期
        //LocalDate date = LocalDate.now();
        //DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd");

        //测试数据
        String httpArg = "2019-12-31";
        try {
   
            Date date = f.parse(httpArg);
        }catch (Exception e){
   
            e.printStackTrace();
        }
        //String httpArg = date.format(formatter);

        Calendar c = Calendar.getInstance();

        //判断今天是否是工作日 周末 还是节假日
        int num =1;
        System.out.println("预计发货需"+num+"天");

        //String httpArg="2020-03-16";//f.format(new Date());
        //String httpArg="$date";// 默认服务器的当前时间


        System.out.println("日期:" + httpArg);

        String n = null;

//        if("0".equals(n)){
   
//            System.out.println("***1***:"+httpArg+"是工作日");
//        }else {
   
//            System.out.println("该日期是非工作日");
//        }
        Date sDate = null;
        try{
   
            //当前日期
            sDate = f.parse(httpArg);

            //if (num !=0) {
   

                for (int i = 0; i < num; i++) {
   
                    c.setTime(sDate);
                    c.add(Calendar.DAY_OF_MONTH, 1);
                    sDate = c.getTime();
                    System.out.println("#####Date+1##### " + f.format(sDate));
                    httpArg = f.format(sDate);
                    n = request(httpArg);
                    if (!"0".equals(n)) {
   
                        num = num + 1;
                        //System.out.println("***1***:"+httpArg+"是工作日");
                    }
                }
           // }
            //sDate = f.parse(httpArg);
            //long year = sDate.getYear()+1900;


            //SimpleDateFormat f1=new SimpleDateFormat("MM月dd日");
            //System.out.println("预计"+f1.format(sDate)+"天发货");



        }catch (Exception e)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值