js得到两日期间的天数
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><script type="text/javascript"> var getOffDays = function(startDate, endDate) { var mmSec = (endDate.getTime() - startDate.getTime()); //得到时间戳相减 得到以毫秒为单位的差 return (mmSec / 3600000 / 24); //单位转换为天并返回 }; alert(getOffDays(new Date(2009,1,1), new Date(2009,2,1))); alert(getOffDays(new Date(2009,2,1), new Date(2009,3,1))); alert(getOffDays(new Date(2009,11,1), new Date(2009,12,1))); alert(getOffDays(new Date(2009,11,10), new Date(2009,12,10)));</script></head><body></body></html>
页:
[1]