namespace Work2
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
MyDateTime mdt = new MyDateTime();
mdt.GetDayNumberOfYear();
Console.ReadKey();
}
class MyDateTime
{
public void GetDayNumberOfYear()
{
while(true){
Console.WriteLine("请输入日期");
//接受用户输入的日期字符串
string date=Console.ReadLine();
//创建一个DateTime的对象
DateTime dt = new DateTime();
//捕捉异常输入
try
{
//把指定的字符串转化为其等效的 DateTime
dt = DateTime.Parse(date);
int year = dt.Year;
DateTime dt1 = new DateTime(year, 1, 1);
int days = (dt.Date - dt1.Date).Days + 1;
//将计算的时期以字符串型是输出
Console.WriteLine(string.Format("今天是今年的第{0}天",days.ToString()));
}
catch(Exception ex)
{
//异常处理
Console.WriteLine(ex.Message);
}
}
}
}
}
}