<pre name="code" class="csharp">{
class Program
{
static void Main(string[] args)
{
Time t = new Time();
try
{
Console.WriteLine("请输入小时");
t.Hour = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入分钟");
t.Minute = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入秒");
t.Second = Convert.ToInt32(Console.ReadLine());
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
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();
Console.ReadKey();
}
}
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());
}
}
}
MyMath
最新推荐文章于 2021-10-24 02:37:18 发布