# MyMath

<pre name="code" class="csharp">{
class Program
{
static void Main(string[] args)
{
Time t = new Time();

try
{
Console.WriteLine("请输入小时");
Console.WriteLine("请输入分钟");
Console.WriteLine("请输入秒");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return;
}

Time T = new Time();

T.hour = DateTime.Now.Hour;
T.minute = DateTime.Now.Minute;
T.second = DateTime.Now.Second;

Console.WriteLine("输入的时间为{0:00}:{1:00}:{2:00}", t.hour, t.minute, t.second);
Console.WriteLine("当前的时间为{0:00}:{1:00}:{2:00}", T.hour, T.minute, T.second);
t.DisPaly();
T.DisPaly();

}
}
class Time
{

public int hour;
public int minute;
public int second;
public int Hour
{
get
{
return Hour;
}
set
{
if (value > 0 && value < 24)

hour = value;

else
{
Console.Clear();
throw new Exception("输入的时间不正确");

}
}
}

public int Minute
{
get
{
return Minute;
}
set
{
if (value > 0 && value < 60)
minute = value;
else
{
Console.Clear();
throw new Exception("输入的时间不正确");
}
}
}
public int Second
{
get
{
return Second;
}
set
{
if (value > 0 && value < 60)
second = value;
else
{
Console.Clear();
throw new Exception("输入的时间不正确");
}
}
}
public int TimePeriod()
{
int a;
a = hour * 3600 + minute * 60 + second;
return a;
}

public void DisPaly()
{
Console.WriteLine("与零时刻的时间间隔:{0}",TimePeriod());

}
}
}  

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客