计算日期并显示 [英] calculate date and display
本文介绍了计算日期并显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个下拉列表,显示从12个月到72个月的月份数.当我选择12个月时,它应该显示从当前日期到指定日期和年份的日期..
假设我选择12个月,则标签应显示:
2012年9月21日至2013年9月21日 这也是必需的日期格式.
这是代码正在执行的操作;
I have a dropdown list that shows the number of months from 12 months upto 72 months.. when i select 12 months it should display the date calculating from current date to the specified date and year..
Suppose i select 12 months then label should display:
21 September 2012 To 21 September 2013 This is the required format of date too.
This is the code am doing now;
function SetDuration() {
try {
var month = document.getElementById("ddlContractDuration").value;
var CurrentDate = new Date();
var toDate = new Date();
toDate.setMonth(Number(toDate.getMonth()) + Number(month));
document.getElementById('txtDuration').value =toDate.toString('mm/dd/yyyy');
}
catch (ex) {
alert(ex.Message());
}
}
但是计算正确,但格式不正确.
but the calculation is correct but the format is not correct.
推荐答案
尝试rhis one.
http://www.west-wind. com/weblog/posts/2008/Mar/18/A-simple-formatDate-function-for-JavaScript [
Hi,
Try rhis one.
http://www.west-wind.com/weblog/posts/2008/Mar/18/A-simple-formatDate-function-for-JavaScript[^]
这篇关于计算日期并显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文