题解 | #计算日期到天数转换#

计算日期到天数转换

http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded

const [ year, month, day ] = readline().split(" ")

const arr = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]

// 闰年分为普通闰年和世纪闰年,其判断方法为:公历年份是4的倍数,且不是100的倍数,为普通闰年。公历年份是整百数,且必须是400的倍数才是世纪闰年。
if( (year % 100 === 0 && year % 400 === 0) || ( year % 4 === 0 && year % 100 !== 0 )) {
  arr[1] = 29
}

const sum = arr.slice(0, month - 1).reduce( ( total, current ) => parseInt(total) + parseInt(current), parseInt(day) )

print( sum )

全部评论

相关推荐

小叮当411:应该是1-3个月吧
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 12:02
ssob上原来真有BOSS啊
硫蛋蛋:这种也是打工的,只不是是给写字楼房东打工
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 11:22
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务