//
// Copyright (c) 2014软件技术1班
// All rights reserved.
// 作 者:A08梁运基
// 完成日期:2014年 12 月 15 日
// 版 本 号:v1.0
//
// 问题描述:创建一个程序来计算当前的时间差。该程序提示用户输入时间值,然后显示出时间差。
// 输入描述:一个实数
// 程序输出:一个结果
//
<pre name="code" class="csharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 时间
{
class Program
{
static void Main(string[] args)
{
Time rectl = new Time();
Time rect2 = new Time();
rect2.Hour = DateTime.Now.Hour;
rect2.Minute = DateTime.Now.Minute;
rect2.Second = DateTime.Now.Second;
try
{
Console.WriteLine("请输入时间小时");
rectl.Hour = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入时间分");
rectl.Minute = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入时间秒");
rectl.Second = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("您所输入的时间为{0}:{1}:{2}", rectl.Hour.ToString("D2"), rectl.Minute.ToString("D2"), rectl.Second.ToString("D2"));
Console.WriteLine("与系统时间相隔为{0}",rectl.TimePeriod(rectl.Hour,rectl.Minute,rectl.Second));
Console.WriteLine("{0}:{1}:{2}",rect2.Hour,rect2.Minute,rect2.Second);
Console.WriteLine("与零时间间隔点时刻为{0}", rect2.TimePeriod(rect2.Hour, rect2.Minute, rect2.Second));
Console.Read();
//double Time;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.Read();
}
}
class Time
{
//public string Time;
private int hour;
public int Hour
{
get
{
return hour;
}
set
{
if (value >= 0 && value <= 24)
hour = value;
else
throw new Exception("时间输入有误");
}
}
private int minute;
public int Minute
{
get
{
return minute;
}
set
{
if (value >= 0 && value <= 60)
minute = value;
else
throw new Exception("时间输入有误");
}
}
private int second;
public int Second
{
get
{
return second;
}
set
{
if (value >= 0 && value <= 120)
second = value;
else
throw new Exception("时间输入有误");
}
}
//private int hour;
//private int minute;
//private int second;
//public void Timea(int hour, int minute, int second)
//{
// if (!(hour > 0 && hour <= 23)) throw new Exception("无效的小时数");
// this.hour = hour;
// this.minute = minute;
// this.second = second;
//}
public int TimePeriod(int hour, int minute, int second)
{
int a;
a = (23 - hour) * 120 + (59 - minute) * 60 + (60 - second);
return a;
}
public void huoqu()
{
hour = DateTime.Now .Hour;
minute = DateTime.Now.Hour;
second = DateTime.Now.Hour;
}
}
}