2010-03-08 3 views
0

안녕하세요. '1 년', '2 년'... 등의 값으로 드롭 다운되었습니다. 또한 나는 캘린더 extender와 함께 두 개의 아약스 텍스트 상자가 있습니다. 드롭 다운 선택 값이 "1 년"이고 두 텍스트 상자 값 사이의 기간이 일치하지 않으면 날짜 경고를 팝업으로 보내고 싶습니다. 무슨 뜻인지 알 겠어? 도와주세요. 어떻게 자바 스크립트에서이 시나리오를 얻을 수 있습니까 ??날짜 차이와 자바 스크립트의 값과 일치

답변

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