<html> <head> <title>ThaiCreate.Com Tutorial</title> </head> <body> <form name="frmMain" action="" method="post"> <script language="JavaScript"> function jsDateDiff1(strDate1,strDate2){ var theDate1 = Date.parse(strDate1)/1000; var theDate2 = Date.parse(strDate2)/1000; var diff=(theDate2-theDate1)/(60*60*24); return diff; } // format MM-DD-YYYY document.write("Date Diff = " + jsDateDiff1("06-01-2012","07-31-2012")+"<br>"); document.write("<hr>") function jsDateDiff2(strDate1,strDate2){ date1 = new Date(strDate1); date2 = new Date(strDate2); var one_day = 1000*60*60*24; var defDate = (date2.getTime() - date1.getTime()) / one_day return defDate; } document.write("Date Diff = " + jsDateDiff2("12 Jan 2012","12 Feb 2012")+"<br>"); // DD MM YYYY document.write("Date Diff = " + jsDateDiff2("12/01/2012","12/02/2012")+"<br>"); // MM/DD/YYYY document.write("<hr>") </script> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท