JavaScript學習(3)使用內建函式和程式庫
阿新 • • 發佈:2019-02-06
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 計算今天到指定日期之間的天數 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<font face = "arial" size = 5 color = red>
<script>
var useryear = eval(prompt("請輸入年(yyyy): ", "2008"));
var usermonth = eval(prompt("請輸入月(mm): ", "8"));
var userday = eval(prompt("請輸入日(dd): ", "1"));
var future = new Date(useryear, usermonth - 1, userday);//計算兩個日期之間的毫秒數差
var today = new Date();
var diff = Math.abs(future.getTime() - today.getTime());
var days = Math.floor(diff / (1000 * 60 * 60 *24));//將毫秒轉換為天數
document.write(today.toLocaleDateString() + "與" + future.toLocaleDateString() + "之間的天數為: " + days + "<br>");
</script>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> 計算今天到指定日期之間的天數 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<font face = "arial" size = 5 color = red>
<script>
var useryear = eval(prompt("請輸入年(yyyy): ", "2008"));
var usermonth = eval(prompt("請輸入月(mm): ", "8"));
var userday = eval(prompt("請輸入日(dd): ", "1"));
var future = new Date(useryear, usermonth - 1, userday);//計算兩個日期之間的毫秒數差
var today = new Date();
var diff = Math.abs(future.getTime() - today.getTime());
var days = Math.floor(diff / (1000 * 60 * 60 *24));//將毫秒轉換為天數
document.write(today.toLocaleDateString() + "與" + future.toLocaleDateString() + "之間的天數為: " + days + "<br>");
</script>
</BODY>
</HTML>