Groovy 中 LocalDate.plusDays() 方法使用错误:字符串转整数
在这段代码中,错误是因为字符串tmp需要使用toInteger()方法将其转换为整数类型,而不仅仅是一个字符串。因此,正确的代码应该是:\n\ngroovy\nString ret = \"2023-08-18\"\nString tmp = \"30\"\nLocalDate date = LocalDate.parse(ret)\ndate = date.plusDays(tmp.toInteger())\n\nString outputDate = date.toString()\nprintln(outputDate)\n\n\n这样,代码就可以正常运行并打印出期望的日期。
原文地址: https://www.cveoy.top/t/topic/qn3F 著作权归作者所有。请勿转载和采集!