i 在两个日期之间产生以下功能:要求核实其正确性,以及如何找到一个月(多到30或31天)和一年。
function days_between(date1, date2,datepart) {
// The number of milliseconds in one day
var ONE_DAY=0;
if ( datepart === undefined ) {
datepart = D ;
iii
if(datepart= Y )
{
ONE_DAY = 1000 * 60 * 60 * 24 * 30 *12
iii
else if (datepart= M )
{
ONE_DAY = 1000 * 60 * 60 * 24 * 30
iii
else
{
ONE_DAY = 1000 * 60 * 60 * 24 //for day
iii
// Convert both dates to milliseconds
var date1_ms = date1.getTime()
var date2_ms = date2.getTime()
// Calculate the difference in milliseconds
var difference_ms = Math.abs(date1_ms - date2_ms)
// Convert back to days and return
return Math.round(difference_ms/ONE_DAY)
iii