Js获取当天年月日

<script type="text/javascript">
    var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    var dateNow = new Date();
    var yearNow = dateNow.getFullYear();
    var monthNow = months[dateNow.getMonth()];
    var dayNow = dateNow.getDate();
    var daySuffix;
    switch (dayNow)
    {
        case 1:
        case 21:
        case 31:
            daySuffix = "st";
            break;
        case 2:
        case 22:
            daySuffix = "nd";
            break;
        case 3:
        case 23:
            daySuffix = "rd";
            break;
        default:
            daySuffix = "th";
            break;
    }
    document.write("It is the " + dayNow + daySuffix + "day"+"<br>");
    document.write("in the month of" + monthNow+"<br>");
    document.write("in the year" + yearNow);

</script>

生成效果为:
 

 

你可能感兴趣的:(职场,休闲,Js获取当天年月日)