ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 ``` /** * <b>方法描述:</b> 格式化日期 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 17:07:19 <br/> * * @param sdate * 入参|输入日期/时间串|{@link java.lang.String} * @param format * 入参|输出格式|{@link java.lang.String} * @param outdate * 出参|输出字符串|{@link java.lang.String} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "格式化日期", style = "判断型", type = "同步组件", comment = "格式化日期", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 05:07:19") @InParams(param = { @Param(name = "sdate", comment = "输入日期/时间串", type = java.lang.String.class), @Param(name = "format", comment = "输出格式", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "outdate", comment = "输出字符串", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_dateFormat(String sdate, String format) { if (sdate == null || sdate.length() < 6) return ResultBase.newFailureResult("TPTD1007", "输入日期不能为空,且不低于6位:" + sdate); if (StringUtil.isBlank(format)) return ResultBase.newFailureResult("TPTD1007", "日期输出格式不能为空"); sdate = sdate.replaceAll("-", ""); sdate = sdate.replaceAll("/", ""); sdate = sdate.replaceAll(":", ""); sdate = sdate.replaceAll(" ", ""); try { String strInFmt = (sdate.length() == 8) ? "yyyyMMdd" : (sdate .length() == 6) ? "HHmmss" : "yyyyMMddHHmmss"; SimpleDateFormat fmtIn = new SimpleDateFormat(strInFmt); Date date = fmtIn.parse(sdate); SimpleDateFormat fmtOut = new SimpleDateFormat(format); return ResultBase.newSuccessResult(fmtOut.format(date)); } catch (Exception ex) { AppLog.error(ex); return ResultBase.newExceptionResult("TPTD1008", "格式化日期异常:输入日期:"+sdate+",输出格式:"+format); } } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/80/9a/809ac9fd17108431aceceec5c03a4b99_1870x892.png) # 参数说明及示例 ## 入口参数 输入日期/时间串:输入一个日期格式的字符串,时间之间用`-、/、:、空格`隔开,示例: `"2020-12-15"` 输出格式:格式化时间的格式,示例: `"yyyy/MM/dd"` ## 出口参数 输出字符串:根据输入参数返回转换后的时间字符串,示例: `__INNER__["result"]`