怎样判断输入的日期是不是一个月的?

natalie_z 2010-01-20 09:29:04
有开始年月日文本框,终止年月日文本框,输入日期后,怎样判断,输入的日期是不是一个月的?
就是说,假如输入 2009年1月1日---2009年4月1日一共三个月就不行,就是说要判断输入的这个日期范围是不是一个月,怎么判断啊?
...全文
95 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmliy 2010-01-20
  • 打赏
  • 举报
回复
一点小错误,重来:


var startDate = '2009年1月1日', endDate = '2009年1月1日';
startDate = startDate.substr(0, startDate.length - 1).replace(/[^0-9]/g, '/');
endDate = endDate.substr(0, endDate.length - 1).replace(/[^0-9]/g, '/');
var d1 = new Date(startDate), d2 = new Date(endDate);
if (!(d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth())) {
alert('不是同一个月');
}
rjzou2006 2010-01-20
  • 打赏
  • 举报
回复
这样的情况只能两日期比较了。
http://http://www.haixiait.com/article.asp?id=5
xmliy 2010-01-20
  • 打赏
  • 举报
回复

var startDate = '2009年1月1日', endDate = '2009年4月1日';
startDate = startDate.substr(0,startDate.length - 2).replace(/[^0-9]/g, '/');
endDate = endDate.substr(0,endDate.length - 2).replace(/[^0-9]/g, '/');
var d1 = new Date(startDate), d2 = new Date(endDate);
if(!(d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth())) {
alert('不是同一个月');
}

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧