Current project: To make a time program in C# with two classes Time and ExtendedTime Time is just the normal time and ExtendedTime has the time zone.
When you start the program I need to click a button and get the current time but there is an option to change the time zone. This in turn changes the time and also has an option to increment the time by so many hours and or minutes.
Currently, this is what my displayTime method in the Time class looks like:
public virtual string displayTime()
{
DateTime time = DateTime.Now; // Use current time
string format = "MMM ddd d HH:mm yyyy"; // Use this format
MessageBox.Show(time.ToString(format)); // Write to console
return time.ToString(format);
}//end of displayTime
Which isn’t bad except that everytime I call it NO MATTER WHAT it will always tell me the current time because of DateTime.Now
I’m not totally sure how to get around that. I’m sure there is a one time deal i can do to do this but not sure of the syntax.
You can use the TimeSpan class to manipulate the DateTime class. For example:
If you’re using a user-supplied time, such as one from a textbox, you can use
Which will give you a DateTime that corresponds to whatever the user enters. Be warned, however, that if the user types in something that the system does not recognize as valid, this will throw an exception.