如何使用javascript从日期输入计算日期? 这是我的代码:
<p>
Start date: <input id="start" name="start" placeholder="Start Date(mm/dd/yyyy)" type="date" />
</p>
<p>
End date: <input id="end" name="end" placeholder="End Date(mm/dd/yyyy)" type="date" />
</p>
我希望通过在结束日期添加17个月来显示日期
答案 0 :(得分:0)
使用以下内容并添加17个月
var myDate = new Date();
myDate.setMonth( myDate.getMonth() + 17 );
alert(myDate);
答案 1 :(得分:0)
使用MomentJS库可以执行以下操作:
<cfcomponent>
<cffunction name="AddUser" access="remote" returnformat="JSON">
<cfargument name="UserID" type="string" required="yes">
<cfset var fncResults = structNew()>
<cfset var recs = StructNew()>
<cfquery name="qryUsers" datasource="UserData">
SELECT UserID, Date, Name, Age, Active
FROM Users
WHERE UserID = <cfqueryparam cfsqltype="cf_sql_integer" value="#UserID#">
ORDER BY Date DESC
</cfquery>
<cfset fncResults.recordcount = qryPlugins.recordcount>
<cfloop query="qryPlugins">
<cfset recs[currentRow] = StructNew()>
<cfset recs[currentRow].UserID = ' ' & qryUsers.UserID>
<cfset recs[currentRow].Date = ' ' & qryUsers.Date>
<cfset recs[currentRow].Name = ' ' & qryUsers.Name>
<cfset recs[currentRow].Age = ' ' & qryUsers.Age>
<cfset recs[currentRow].Active = ' ' & qryUsers.Active>
</cfloop>
<cfset fncResults.status = "200">
<cfset fncResults.data = recs>
<cfelse>
<cfset fncResults.status = "400">
<cfset fncResults.message = "Invalid access attempt">
</cfif>
<cfreturn fncResults>
</cffunction>
</cfcomponent>
答案 2 :(得分:0)
使用JQuery获取结束日期的值,如下所示:
var endDate = $("#end").val();
然后将其变成日期对象:
endDate = new Date(endDate);
然后你可以在这样的日期添加515(365个月12个月,300个额外5个月大约)天:
endDate.setDate(endDate.getDate()+515);