javascript - 如何使用 JQuery 或 Javascript 设置日期类型值的输入
问题描述
我的代码如下:
var date1 = new Date($("#date1").val() + "T00:00");
date1.setDate(date1.getDate() + 30); // 30 days into the future
$date2 = $("#date2"); // input of type date
$date2.val(date1)
除了最后一行之外,所有工作都按预期工作。错误说:
jquery-3.2.1.js:7990 The specified value "2021-07-02T03:00:00.000Z" does not conform to the required format, "yyyy-MM-dd
解决方案
In case someone else has the same issue, this is how I solved it:
$date2.val(date1.toISOString().split("T")[0])
推荐阅读
- apache-spark - 意见:从 Spark 流式传输或结构化流式传输任务中查询数据库
- python - numpy array with diagonal equal to zero and [x,y] =-[y,x]
- python - TypeError: '>' not supported between instances of 'map' and 'int'
- loops - 计算范围内的某些点
- python - 如何配置已在该按钮上使用参数的功能中单击的按钮?
- swift - 循环发布者组合框架
- java - 数据未添加到数据库 SQLITE
- google-cloud-platform - Cloud Run on GKE 自动扩缩
- git - 将主仓库从 Bitbucket 迁移到 Github。如何将克隆的 repo 重新连接到新的 Github repo?
- winforms - SignalR 客户端在第二个会话的 start() 上挂起