本文介绍了如何将月份添加到输入的日期时间值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个文本框,我在其中获取一个日期时间值,例如'7/27/2015 12:00:00 AM',我有一个下拉列表控件,其中包含每月,每季度,每半年,每年的列表。那么如何通过更改下拉期来仅在该日期添加几个月? 我尝试如下,但如果月份超过12,则额外的月份和年份不会改变。 b $ b 我的尝试:I have one textbox in which i am getting one datetime value for example '7/27/2015 12:00:00 AM', and I have one dropdown list control with the list of Monthly,Quarterly,HalfYearly,Yearly. So how to add only months on that date by changing the dropdown periods?I tried like below but getting extra months and year not changing if month get above 12.What I have tried:var d = new Date($("#<%=txtActDate.ClientID%>").val()); var curr_date = d.getDate(); if (packPeriod == 'Monthly') { var curr_month = d.getMonth() + 1; var curr_year = d.getFullYear(); var dates = curr_date + "/" + curr_month + "/" + curr_year; alert(dates ); } else if (packPeriod == 'Quarterly') { var curr_month = d.getMonth() + 3; var curr_year = d.getFullYear(); var dates = curr_date + "/" + curr_month + "/" + curr_year; alert(dates ); } else if (packPeriod == 'HalfYearly') { var curr_month = d.getMonth() + 6; var curr_year = d.getFullYear(); var dates = curr_date + "/" + curr_month + "/" + curr_year; alert(dates ); } else if (packPeriod == 'Yearly') { var curr_month = d.getMonth() + 12; var curr_year = d.getFullYear(); var dates = curr_date + "/" + curr_month + "/" + curr_year; alert(dates ); }推荐答案(#<%= txtActDate.ClientID%>)。val()); var curr_date = d.getDate(); if(packPeriod =='Monthly'){ var curr_month = d.getMonth()+ 1; var curr_year = d.getFullYear(); var dates = curr_date +/+ curr_month +/+ curr_year; 提醒(日期); } else if(packPeriod =='Quarterly'){ var curr_month = d.getMonth()+ 3; var curr_year = d.getFullYear(); var dates = curr_date +/+ curr_month +/+ curr_year; 提醒(日期); } else if(packPeriod =='HalfYearly'){ var curr_month = d.getMonth()+ 6; var curr_year = d.getFullYear(); var dates = curr_date +/+ curr_month +/+ curr_year; 提醒(日期); } else if(packPeriod =='Yearly'){ var curr_month = d.getMonth()+ 12; var curr_year = d.getFullYear(); var dates = curr_date +/+ curr_month +/+ curr_year; 提醒(日期); }("#<%=txtActDate.ClientID%>").val()); var curr_date = d.getDate(); if (packPeriod == 'Monthly') { var curr_month = d.getMonth() + 1; var curr_year = d.getFullYear(); var dates = curr_date + "/" + curr_month + "/" + curr_year; alert(dates ); } else if (packPeriod == 'Quarterly') { var curr_month = d.getMonth() + 3; var curr_year = d.getFullYear(); var dates = curr_date + "/" + curr_month + "/" + curr_year; alert(dates ); } else if (packPeriod == 'HalfYearly') { var curr_month = d.getMonth() + 6; var curr_year = d.getFullYear(); var dates = curr_date + "/" + curr_month + "/" + curr_year; alert(dates ); } else if (packPeriod == 'Yearly') { var curr_month = d.getMonth() + 12; var curr_year = d.getFullYear(); var dates = curr_date + "/" + curr_month + "/" + curr_year; alert(dates ); }在这篇文章中看看bmpasini的答案 - Javascript函数将X个月添加到日期 - Stack Overflow [ ^ ] NB - 最受欢迎(和接受)的解决方案实际上无法正常工作 - 使用bmpasini中的一个Have a look at the answer from bmpasini on this post - Javascript function to add X months to a date - Stack Overflow[^]NB - the most popular (and the accepted) solution doesn't actually work properly - use the one from bmpasini 这篇关于如何将月份添加到输入的日期时间值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 06:20