我从API获得一个字符串类型的date,然后将它解析为date类型,这样我就可以使用它进行倒计时。
我希望在从API获得的日期基础上再增加30天。
下面是我解析的代码
const time = Date.parse("2020-12-30T18:35:43");我已经读过这个问题了,我试着去实现它
但是react不能识别getDate
如果您需要更多信息,请让我知道。
发布于 2021-01-08 03:30:10
您需要用new Date()包装已解析的日期
const time = new Date(Date.parse("2020-12-30T18:35:43"));
// As mention by other comments, this is enough
// const time = new Date("2020-12-30T18:35:43");
time.setSeconds(time.getSeconds() + 10) // 1609349753000setSeconds和getSeconds是Date的方法,您试图在一个数字上执行它们。
编辑:
答案可以在一般情况下找到,你应该使用here -fns来进行日期操作;)
发布于 2021-01-08 03:33:35
您也可以setDate到您现有的日期。检查以下代码。
const date = new Date("2020-12-30T18:35:43");
date.setDate(date.getDate() + 30);https://stackoverflow.com/questions/65618663
复制相似问题