시간 대 길 이 를 비교 하여 비교적 긴 시간 을 시간 으로 바꾸다.

<html>
<head>
<title>       ,           </title>
</head>

<body>
<span>   14:00-16:00    14:00-16:30  ,          </span><span id="duration"></span><span>  。</span>
</body>

<script language="javascript">
function calculateMeetDuration() {
var year=2014, month=1, day=10;
//       ,14:00 - 16:00
var planStartHour = "14:00".split(":")[0] * 1;
var planStartMinute = "14:00".split(":")[1] * 1;
var planEndHour = "16:00".split(":")[0] * 1;
var planEndMinute = "16:00".split(":")[1] * 1;

//       ,14:00 - 16:30
var actStartHour = "14:00".split(":")[0] * 1;
var actStartMinute = "14:00".split(":")[1] * 1;
var actEndHour = "16:30".split(":")[0] * 1;
var actEndMinute = "16:30".split(":")[1] * 1;

//            
var planStart = new Date(year, month, day, planStartHour, planStartMinute); 
var planEnd = new Date(year, month, day, planEndHour, planEndMinute);
var planMs = planEnd.getTime() - planStart.getTime();

//            
var actStart = new Date(year, month, day, actStartHour, actStartMinute); 
var actEnd = new Date(year, month, day, actEndHour, actEndMinute);
var actMs = actEnd.getTime() - actStart.getTime();

//           ,             
var meetDuration = 0;
if (planMs >= actMs) {
meetDuration = planMs / 1000 / 60 / 60;
} else {
meetDuration = actMs / 1000 / 60 / 60;
}
duration.innerHTML = meetDuration.toFixed(1); //       
}

calculateMeetDuration();
</script>
</html>

좋은 웹페이지 즐겨찾기