码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript判断输入的日期是今年的第几天

时间:2018-05-20 18:12:54      阅读:181      评论:0      收藏:0      [点我收藏+]

标签: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判断输入的日期是今年的第几天

标签:console   rip   const   line   read   javascrip   一个   code   OLE   

原文地址:https://www.cnblogs.com/cj-18/p/9063807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!