Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

javascript - 在javascript中的另一个文本框中找不到两个日期之间的差异(couldn't find the difference between two date in another textbox in javascript)

my date format is dd/mm/yyyy and calculate this format(我的日期格式是dd / mm / yyyy并计算此格式)

here a script(这是一个脚本) <script type="text/javascript"> function GetDays() { var dropdt = new Date(document.getElementById("sdate").value); var pickdt = new Date(document.getElementById("edate").value); var difference = edate - sdate; return Math.round(difference / 1000 * 3600 * 24); } function cal() { document.getElementById("numdays2").value = GetDays(); } </script>   ask by Hitendra Patil translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you need to get time from date and then do the calculation(您需要从日期获取时间,然后进行计算)

var date1 = new Date("06/30/2019"); var date2 = new Date("07/30/2019"); // To calculate the time difference of two dates var Difference_In_Time = date2.getTime() - date1.getTime(); // To calculate the no. of days between two dates var Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24); //To display the final no. of days (result) console.log("Total number of days between dates <br>" + date1 + "<br> and <br>" + date2 + " is: <br> " + Difference_In_Days);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...