![](/img/trans.png)
[英]How to convert a string eg: '8/31/2020' to a date, and substract it from todays date to find number of days that have passed in JavaScript
[英]How to add number of days to todays date ?(.ics file generator)
我正在尋找為我的活動添加動態日期的最簡單方法。
(function() {
document.querySelector("#startDate").valueAsDate = new Date();
document.querySelector("#endDate").valueAsDate = new Date();
document.querySelector("#endDate").min = new Date()
.toISOString()
.substr(0, 10);
我期待能夠簡單地添加日期,但我想不出一種方法來做到這一點。
您可以使用.getDate()
和.setDate()
向任何Date
object 添加天數:
const today=new Date(), in10days=new Date(); in10days.setDate(in10days.getDate()+10); console.log("today:",today.toISOString()) console.log("in 10 days:",in10days.toISOString());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.