C#程序设计?自定义一个时间类,该类包含时,分,秒字段与属性,具有将时间增加1秒,1分,1小时的方法,具
C#自定义一个时间类,该类包含时,分,秒字段与属性,具有将时间增加1秒,1分,1小时的方法,具有分别显示时,分,秒同时显示时分秒的方法...
C#自定义一个时间类,该类包含时,分,秒字段与属性,具有将时间增加1秒,1分,1小时的方法,具有分别显示时,分,秒同时显示时分秒的方法
展开
2个回答
展开全部
class MyDate
{
int hour;
public int Hour
{
get { return hour; }
set { hour = value; }
}
int min;
public int Min
{
get { return min; }
set { min = value; }
}
int sec;
public int Sec
{
get { return sec; }
set { sec = value; }
}
public DateTime AddSecond()
{
return DateTime.Now.AddSeconds(1);
}
public DateTime AddMin()
{
return DateTime.Now.AddMinutes(1);
}
public DateTime AddHour()
{
return DateTime.Now.AddHours(1);
}
public string ShowSecond()
{
return DateTime.Now.Second.ToString();
}
public string ShowMin()
{
return DateTime.Now.Minute.ToString();
}
public string ShowHour()
{
return DateTime.Now.Hour.ToString();
}
public string ShowAll()
{
return DateTime.Now.Hour.ToString() +":"+ DateTime.Now.Minute.ToString() +":"+ DateTime.Now.Second.ToString();
}
}
本人纯手写,原创答案
{
int hour;
public int Hour
{
get { return hour; }
set { hour = value; }
}
int min;
public int Min
{
get { return min; }
set { min = value; }
}
int sec;
public int Sec
{
get { return sec; }
set { sec = value; }
}
public DateTime AddSecond()
{
return DateTime.Now.AddSeconds(1);
}
public DateTime AddMin()
{
return DateTime.Now.AddMinutes(1);
}
public DateTime AddHour()
{
return DateTime.Now.AddHours(1);
}
public string ShowSecond()
{
return DateTime.Now.Second.ToString();
}
public string ShowMin()
{
return DateTime.Now.Minute.ToString();
}
public string ShowHour()
{
return DateTime.Now.Hour.ToString();
}
public string ShowAll()
{
return DateTime.Now.Hour.ToString() +":"+ DateTime.Now.Minute.ToString() +":"+ DateTime.Now.Second.ToString();
}
}
本人纯手写,原创答案
展开全部
你的描述不够具体,所以不知道这个写的合不合适,只是根据你的大体意思写的
/// <summary>
/// Time 的摘要说明
/// </summary>
public class Time
{
//无参构造方法
public Time() { }
//有参构造方法
public Time(int hour, int minute, int second)
{
this.Hour = hour;
this.Minute = minute;
this.Second = second;
}
//时
private int hour;
public int Hour
{
get { return hour; }
set { hour = value; }
}
//分
private int minute;
public int Minute
{
get { return minute; }
set { minute = value; }
}
//秒
private int second;
public int Second
{
get { return second; }
set { second = value; }
}
//把时分秒都加1
public void AddAll(int hour, int minute, int second)
{
hour += 1;
minute += 1;
second += 1;
}
//显示时
public string ShowHour(int hour)
{
return hour.ToString();
}
//显示分
public string ShowMinute(int minute)
{
return minute.ToString();
}
//显示秒
public string ShowSecond()
{
return second.ToString();
}
/// <summary>
/// 显示时分秒的方法
/// </summary>
/// <param name="hour"></param>
/// <param name="minute"></param>
/// <param name="second"></param>
/// <returns></returns>
public string ShowAll(int hour, int minute, int second)
{
return hour.ToString() + ":" + minute.ToString() + ":" + second.ToString();
}
}
/// <summary>
/// Time 的摘要说明
/// </summary>
public class Time
{
//无参构造方法
public Time() { }
//有参构造方法
public Time(int hour, int minute, int second)
{
this.Hour = hour;
this.Minute = minute;
this.Second = second;
}
//时
private int hour;
public int Hour
{
get { return hour; }
set { hour = value; }
}
//分
private int minute;
public int Minute
{
get { return minute; }
set { minute = value; }
}
//秒
private int second;
public int Second
{
get { return second; }
set { second = value; }
}
//把时分秒都加1
public void AddAll(int hour, int minute, int second)
{
hour += 1;
minute += 1;
second += 1;
}
//显示时
public string ShowHour(int hour)
{
return hour.ToString();
}
//显示分
public string ShowMinute(int minute)
{
return minute.ToString();
}
//显示秒
public string ShowSecond()
{
return second.ToString();
}
/// <summary>
/// 显示时分秒的方法
/// </summary>
/// <param name="hour"></param>
/// <param name="minute"></param>
/// <param name="second"></param>
/// <returns></returns>
public string ShowAll(int hour, int minute, int second)
{
return hour.ToString() + ":" + minute.ToString() + ":" + second.ToString();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询