比较日期的持续时间与选定的下拉值...请阅读

时间:2010-03-08 09:01:10

标签: date duration

我的下载价值为“一年”,“两年”,......等等。好吗?我还有两个带日历扩展器的ajax文本框。如果下拉选择值为“一年”,并且两个文本框值之间的持续时间意味着日期不匹配,我想弹出警报消息。得到我的意思?请帮帮我。

1 个答案:

答案 0 :(得分:0)

Algorithm :
1.Get the both date from the text box.
2. The find the epcoch time for each date. //
3. subtract the both dates.
4. subtract_result = 365*24*60*60  // Finding the 1 year timestamp values
5. So, it the difference exceed than above calculation , you could sure that the date is mis matching.
 

// This is for first date first = new Date(2010, 03, 08, 15, 30, 10); // Get the first date epoch object // document.write((first.getTime())/1000); // get the actual epoch values second = new Date(2012, 03, 08, 15, 30, 10); // Get the first date epoch object //document.write((second.getTime())/1000); // get the actual epoch values diff= second - first ; one_day_epoch = 24*60*60 ; // calculating one epoch if ( diff/ one_day_epoch > 365 ) // check , is it exceei { alert( 'date is exceeding one year'); }