swift计算 switch case

var year = 2016
var month = 7
var day = 6;
let daysOfFeb = year % 4 == 0 && year%100  != 0 || year % 400 == 0 ?29:28
var count = 0 // 定义一个变量 代表结果
switch month{
case 12:count += 30; fallthrough
case 11:count += 31; fallthrough
case 10:count += 30; fallthrough
case 9:count += 31; fallthrough
case 8:count += 31; fallthrough
case 7:count += 30; fallthrough
case 6:count += 31; fallthrough
case 5:count += 30; fallthrough
case 4:count += 31; fallthrough
case 3:count += daysOfFeb; fallthrough
case 2:count += 31; fallthrough
    case 1:count += day
default:break
}
print("\(year)年\(month)月\(day)日 是一年当中的第\(count)天")

 

posted @ 2016-07-06 15:34  。低调ヽ继续  阅读(192)  评论(0编辑  收藏  举报