企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件源码 ``` /** * <b>方法描述:</b> 计算时间差(字符串) <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2020-12-18 10:06:32 <br/> * * @param time1 * 入参|源时间串(yyyyMMddHHmmss)|{@link java.lang.String} * @param time2 * 入参|目标时间串(yyyyMMddHHmmss)|{@link java.lang.String} * @param unit * 入参|时间单位(seconds/minutes/hours/days)|{@link java.lang.String} * @param diff * 出参|差值|{@link int} * @return -1 异常<br/> * 1 成功<br/> */ @Component(label = "计算时间差(字符串)", style = "判断型", type = "同步组件", comment = "计算两个字符串时间的差值,返回正整数", version = "1.0.0", deprecated = false, author = "admin", date = "2020-12-18 10:06:32") @InParams(param = {@Param(name = "time1", comment = "源时间串(yyyyMMddHHmmss)", type = java.lang.String.class), @Param(name = "time2", comment = "目标时间串(yyyyMMddHHmmss)", type = java.lang.String.class), @Param(name = "unit", comment = "时间单位(seconds/minutes/hours/days)", type = java.lang.String.class)}) @OutParams(param = {@Param(name = "diff", comment = "差值", type = int.class)}) @Returns(returns = {@Return(id = "-1", desp = "异常"), @Return(id = "1", desp = "成功")}) @Order(value = 2) public static ResultBase P_timeDiff(String time1, String time2, String unit) { try { SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss"); Date begDate = fmt.parse(time1); Date endDate = fmt.parse(time2); long nRet = begDate.getTime() - endDate.getTime(); nRet = nRet / 1000; if ("minutes".equalsIgnoreCase(unit)) { nRet = nRet / 60; } else if ("hours".equalsIgnoreCase(unit)) { nRet = (nRet / 60) / 60; } else if ("days".equalsIgnoreCase(unit)) { nRet = ((nRet / 60) / 60) / 24; } return ResultBase.newSuccessResult(Math.abs(nRet)); } catch (Exception ex) { AppLog.error(ex); return ResultBase.newExceptionResult("TPTD1004", "计算事件差异常:" + AppLog.errorMsg(ex)); } } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/42/b8/42b8fa0e0e044158929619ce279bb60d_1869x892.png) # 参数说明及示例 ## 入口参数 源时间串(yyyyMMddHHmmss):输入指定格式的日期字符串,示例: `"20201115000000"` 目标时间串(yyyyMMddHHmmss):输入指定格式的日期字符串,示例: `"20201012000000"` 时间单位(seconds/minutes/hours/days):计算结果以什么时间单位显示,示例: `"days"` ## 出口参数 差值:根据输入参数计算后的结果,示例: `__INNER__["result"]`