ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 ``` /** * <b>方法描述:</b> 计算时间差(字符串) <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-04-13 16:51:53 <br/> * * @param time1 * 入参|时间1|{@link java.util.Date} * @param time2 * 入参|时间2|{@link java.util.Date} * @param unit * 入参|时间单位(seconds/minutes/hours/days)|{@link java.lang.String} * @param diff * 出参|差值|{@link int} * @return -1 异常<br/> * 1 成功<br/> */ @Component(label = "计算时间差(Date)", style = "判断型", type = "同步组件", comment = "计算两个Date时间的差值", version = "1.0.0", deprecated = false, author = "admin", date = "2018-04-13 04:51:53") @InParams(param = { @Param(name = "time1", comment = "时间1", type = java.util.Date.class), @Param(name = "time2", comment = "时间2", type = java.util.Date.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 = "成功") }) public static ResultBase P_dateDiff(Date time1, Date time2, String unit) { try { long nRet = time1.getTime() - time2.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("TPTD1005", "P_dateDiff-输入日期字符串格式错误"); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/72/53/725396a1d70c9d6b5088f7f684e1c819_1868x891.png) # 参数说明及示例 ## 入口参数 时间1:输入一个 date 类型的日期,示例: `__INNER__["date1"]` 时间2:输入一个 date 类型的日期,示例: `__INNER__["date2"]` 时间单位(seconds/minutes/hours/days):计算结果以什么时间单位显示,示例: `"days"` ## 出口参数 差值:根据输入参数计算后的结果,示例: `__INNER__["result"]`