JavaScript判斷輸入的日期是今年的第幾天

來源:互聯網
上載者:User

標籤:console   rip   const   line   read   javascrip   一個   code   OLE   

const readline = require("readline-sync");console.log("請輸入一個年份:");let year = readline.question()-0;while (isNaN(year) || year < 1 || year > 2018) {    console.log("年份輸入有誤");    year = readline.question()-0;} console.log("請輸入一個月份:");let month = readline.question()-0;while (isNaN(month) || month < 1 || month > 12) {    console.log("月份輸入有誤");    month = readline.question()-0;} console.log("請輸入一個日期:");let day = readline.question()-0;while (isNaN(day) || day < 1 || day >31) {    console.log("日期輸入有誤");    day = readline.question()-0;} let alldays = 0;switch (month - 1) {    case 11:        alldays += 30;    case 10:        alldays += 31;    case 9:        alldays += 30;    case 8:        alldays += 31;    case 7:        alldays += 31;    case 6:        alldays += 30;    case 5:        alldays += 31;    case 4:        alldays += 30;    case 3:        alldays += 31;    case 2:        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {            alldays += 29;        } else {            alldays += 28;        }    case 1:        alldays += 31;        break;}console.log(`${year}年${month}月${day}日是今年的第${alldays+day}天`);

 

JavaScript判斷輸入的日期是今年的第幾天

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.