By Bostjan Maroh
Introduction
The idea comes when i must create a project that work lots with time. So i have create time class. With this class you can calculate (sum) times, convert times from and to other data types.
Time class is writen in C# and .NET 2.0.
Time class explantation.
This is simple class and is not much to explain.
1.Public fields:
.public int Hour,
.public int Minute and
.public int Second.
.public const char TIME_SEPERATOR = ':'
2.Constructors:
.current system time (public Time()),
.from string value (public Time(string value)),
.from parameters (public Time(int hour, int minute, int second)) and
.from seconds (public Time(int seconds)).
3.
Public method Add:
Example 1:
InDoc.Systems.Time time1 = new InDoc.Systems.Time("12:00:55");
// calculate 12:00:55 + 14:55:20
time1.Add("14:55:20");
// result: 26:56:15
4. To addition two times you can use + and to subtraction you can use -.
Example 2:
InDoc.Systems.Time time1 = new InDoc.Systems.Time("12:00:55") +
new InDoc.Systems.Time("14:55:20");
// result: 26:56:15
InDoc.Systems.Time time2 = new InDoc.Systems.Time("14:55:20") .
new InDoc.Systems.Time("12:00:55");
// result: 02:54:25
5. We have some convert methods:
.public int ToSeconds(),
.public override string ToString()
and static method that convert secontd to Time object:
.public static Time GetTimeFromSeconds(int seconds).
Download Source
Conclusion
If you have lots to do with times, you will save your time with this class.
If you have any suggestions or questions let me know.