Workday Computing Tool

Before writing some business logic, there are some logic to calculate the workday. It's different every time. Recently, I took time to write an interface and hang it on the server. For brothers in need.


1. Method Description:


The address above is the afterWorkDay interface that is called to calculate the dates of several working days in the future. The example means calculating the date of the third working day after September 5, 2019. The last two parameters can be filled in according to the actual situation.



This method is the same as the first method passing parameters. But it calculates the number of working days before a certain day. The example means calculating the date of September 5, 2019 and pushing forward three working days.



This method calculates how many working days are separated between two dates. It should be noted that the first date parameter needs to be smaller than the second date parameter or return 0.


2. Use method:

The server returns an object as follows: {"id": 20842, "workdate", "2019-08-28", "week_day": 3, "isHoliday": 0}

IDS need not be ignored. workdate is the target date. Wednesday is Wednesday, and Wednesday is Wednesday. Is it Holiday a holiday? 0 is not a holiday.


If you use java. Here's an encapsulated class. Then refer to the direct call in the main method.


The code is as follows:

import java.util.List;
import java.util.Map;


public class WebServiceTest {
	public static String afterWorkDay(String startDate , int distance) {
		return sendGet("afterWorkDay/"+startDate+"/"+distance);
	public static String beforeWorkDay(String startDate , int distance) {
		return sendGet("beforeWorkDay/"+startDate+"/"+distance);
	public static String calcWorkDay(String startDate , String endDate) {
		return sendGet("calcWorkDay/"+startDate+"/"+endDate);
     * Send a GET method request to the specified URL
     * @param url
     *            The URL to send the request
     * @param param
     *            The request parameter should be in the form of name1 = value1 & Name2 = value2.
     * @return URL Response results of the remote resources represented
    public static String sendGet(String param) {
    	String url = "";
        String result = "";
        BufferedReader in = null;
        try {
            String urlNameString = url + "/" + param;
            URL realUrl = new URL(urlNameString);
            // Open the connection between the URL
            URLConnection connection = realUrl.openConnection();
            // Setting Common Request Properties
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // Establish actual connections
            // Get all response header fields
            //Map<String, List<String>> map = connection.getHeaderFields();
            // Traverse through all response header fields
            //for (String key : map.keySet()) {
            //   System.out.println(key + "--->" + map.get(key));
            // Define the BufferedReader input stream to read the response of the URL
            in = new BufferedReader(new InputStreamReader(
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
        } catch (Exception e) {
            System.out.println("Send out GET The request is abnormal!" + e);
        // Close the input stream using the final block
        finally {
            try {
                if (in != null) {
            } catch (Exception e2) {
        return result;
    public static void main(String[] args) {
		//Objects returned by the output server
    	System.out.println(afterWorkDay("2019-8-24", 3));
		//This is to turn the return object into a json object, using Ali's fastjson package
    	JSONObject data = JSONObject.parseObject(afterWorkDay("2019-8-24", 3));
		//When converted into a json object, the corresponding attributes can be obtained.


Welcome comments

Tags: Java JSON Windows

Posted on Wed, 04 Sep 2019 19:38:03 -0700 by jrmckee