using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 闰年练习
{
class Program
{
static void Main(string[] args)
{
//1、输入年月日,看输入的日期是否正确
//2、输出是今年是否是闰年(29天),输出日期
// 闰年的判断普通年能被4整除且不能被100整除的为闰年
// 世纪年能被400整除的是闰年
//3、输出是今年的第几天
//提示用户输入日期
DateTime dt = new DateTime();
int a = dt.Year;//定义年的变量是a
int b = dt.Month;//定义月的变量是b
int c = dt.Day;//定义日的变量是c
Console.Write("请输入日期:");
try//异常语句处理,判断用户输入是否正确,如果正确执行下面内容
{
string s = Console.ReadLine();
dt = DateTime.Parse(s);
s = dt.ToString("yyyy年MM月dd日");
if ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0)
{
Console.WriteLine("今年是闰年!");
}
else
{
Console.WriteLine("今年不是闰年!");
}
string x = dt.DayOfWeek.ToString();//将英文星期几转换为中文
switch(x)
{
case "Monday": x = "星期一"; break;
case "Tuesday": x = "星期二"; break;
case "Wednesday": x = "星期三"; break;
case "Thursday ": x = "星期四"; break;
case "Friday": x = "星期五"; break;
case "Saturday": x = "星期六"; break;
case "Sunday": x = "星期七"; break;
}
Console.WriteLine("您输入的日期是" + a + "年的第" + (dt.DayOfYear) + "天!" + "\t" + x);
}
catch//用户输入错误
{
Console.WriteLine("对不起,您输入的日期不正确!");
}
Console.ReadLine();
}
}
}