Jay B. Harlow said:
Fritz,
Can you give a more complete example of what you are doing, and what you
expect?
Thanks Jay, here is more detail.
I'm using a random function that adds (- minutes) to the current time.
PickTime returns a negative number between 1-120. When the value is
returned the newTime is okay but just gives me total minutes , I just want
to format the result in hh:mm format. So if 95 minutes is returned I want
newTime to be "01:35" or if 46 is returned "00:46".
sting newTime =DateTime.Now.AddMinutes(-PickTime()).ToString();
So in your example:
Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
I'm looking to get 00:45 returned rather than.
-45: 7/19/2004 9:52:57 AM
It is being used as a "simulation", the value is attached to a timertick and
gets updated as time progresses. This seeds a value and the elapsed time is
updated with each tick, in this case, I'm updating a display every minute So
after 20 minutes the display using the above example of -45 I want the
value to be 01:05 (45+20 minutes or 1 hr 20 minutes)
hope that helps.
As using the following:
Debug.WriteLine(DateTime.Now.AddMinutes(30), "30");
Debug.WriteLine(DateTime.Now.AddMinutes(90), "90");
Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
I get:
30: 7/19/2004 11:07:57 AM
90: 7/19/2004 12:07:57 PM
-45: 7/19/2004 9:52:57 AM
To limit the returned value to HH:MM I would use the ToString method
with
a
custom format, something like:
Debug.WriteLine(DateTime.Now.AddMinutes(30).ToString("hh:mm"), "30")
"90")
Debug.WriteLine(DateTime.Now.AddMinutes(-45).ToString("hh:mm"),
"-45")
30: 11:10
90: 12:10
-45: 09:55
For details on custom datetime formats see:
http://msdn.microsoft.com/library/d...s/cpguide/html/cpcondatetimeformatstrings.asp
For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconformattingtypes.asp