企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件源码 ``` /** * <b>方法描述:</b> 转换日期对象 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 17:08:34 <br/> * * @param dateobj * 入参|输入日期|{@link Object} * @param outdate * 出参|返回日期|{@link Object} * @return -1 异常<br/> * 1 成功<br/> */ @Component(label = "转换日期对象", style = "判断型", type = "同步组件", comment = "根据字符串转日期对象;根据日期对象转字符串;输入为空获取当前时间对象", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 05:08:34") @InParams(param = { @Param(name = "dateobj", comment = "输入日期", type = Object.class) }) @OutParams(param = { @Param(name = "outdate", comment = "返回日期", type = Object.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "1", desp = "成功") }) public static ResultBase P_getDateTime(Object dateobj) { Object objRet = null; if (dateobj == null) { objRet = new Date(); } else if (dateobj instanceof String) { String sdate = (String) dateobj; sdate = sdate.replaceAll("-", ""); sdate = sdate.replaceAll("/", ""); sdate = sdate.replaceAll(":", ""); sdate = sdate.replaceAll(" ", ""); if (sdate.length() < 1) { objRet = new Date(); } else { try { String strInFmt = (sdate.length() == 8) ? "yyyyMMdd" : (sdate.length() == 6) ? "HHmmss" : "yyyyMMddHHmmss"; SimpleDateFormat fmtIn = new SimpleDateFormat(strInFmt); objRet = fmtIn.parse(sdate); } catch (Exception ex) { AppLog.error(ex); return ResultBase.newExceptionResult("TPTD1009", "["+objRet+" ]日期不合法,转换错误"+AppLog.errorMsg(ex)); } } } else if (dateobj instanceof Date) { try { SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); s.setLenient(false); objRet = s.format(dateobj); } catch (Exception ex) { AppLog.error(ex); return ResultBase.newExceptionResult("TPTD1010", "["+objRet+" ]日期不合法,转换错误"+AppLog.errorMsg(ex)); } } return ResultBase.newSuccessResult(objRet); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/b2/cf/b2cf4f9b91d839a0b1bc2b43db13455e_1869x892.png) # 参数说明及示例 ## 入口参数 输入日期:输入一个 date 类型的日期或者日期字符串,示例: `"2020-12-23"` ## 出口参数 返回日期:根据字符串转日期对象,根据日期对象转字符串,输入为空获取当前时间对象,示例: `__INNER__["date"]`