【发布时间】:2023-04-01 21:29:01
【问题描述】:
我有以下 JAVA 代码
public static String getstartDateEvent (int addDay) {
Calendar today = Calendar.getInstance();
today.add(Calendar.DATE,addDay);
int year = today.get(Calendar.YEAR);
int month = today.get(Calendar.MONTH);
int day = today.get(Calendar.DATE);
Date date = new Date(year - 1900, month, day);
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
String fileDate = formatter.format(date);
return fileDate;
}
运行代码后出现以下错误:
在播放脚本 [TestScripts.Test_applications] [CRFCN0019E: RationalTestScriptException on line 0 of script TestScripts.BlankScript - java.lang.IllegalArgumentException: 无法将给定对象格式化为日期时发生异常。]。
我需要帮助检查该方法,我有一个调用此方法的主脚本,其中 addDay 需要改变的能力。需要返回,因为在主脚本中它将日期发送到另一个方法。我正在使用脚本进行测试自动化
更新
我试图在代码中自动插入日期,所以今天是 2011 年 10 月 21 日,我需要自动更改可能 27 天后的日期。在日历方法中,无法更改格式,而在日期方法中,没有选项可以添加到当前日期。
【问题讨论】:
-
尚不清楚为什么要提取这些字段...为什么不直接使用
formatter.format(today.getTime())?也不清楚 what 在这里失败了。你的测试代码在做什么? -
这和函数式编程有什么关系?
-
它应该说我正在使用的 IBM 程序的理性功能测试器。我更新了问题。
标签: java simpledateformat