2010-03-08 49 views
0

嗨,我把價值下拉爲「一年」,「兩年」,等等..好嗎?我還有兩個帶日曆擴展器的ajax文本框。如果下拉選擇值爲「一年」,並且兩個文本框值之間的持續時間均表示日期不匹配,我想彈出警報消息。明白我的意思?請幫幫我。 我怎樣才能得到這個場景在JavaScript?日期差異和匹配的值在JavaScript中

回答

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.

Javascript: // 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'); }