今天:new Date()

毫秒:new Date(milliseconds)

字串:new Date("1991/08/22")

時間:new Date(1998, 2, 04)


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>05DateObject.html</title>

    <script>

        var d = new Date();

        //var d = new Date(1000*46*365*24*60*60);

        //var d = new Date("1991/08/22");

        var m = new Date(1998, 2, 04)//注意一月是0、十二月是11

        document.write(m+"<br>")

 

        var theYear = d.getFullYear() - 1911;//民國

        var theMonth = d.getMonth() + 1;//月份從0開始

        var theDate = d.getDate();

        //document.write(d);

        document.write("民國" + theYear + "" + theMonth + "" + theDate + "" + "<br>");

 

        var y = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);//尋找昨天

        alert("昨天日期:"+y);

 

    </script>

</head>

<body>

 

</body>

</html>

 

乙方 發表在 痞客邦 留言(0) 人氣()