time difference

  • Thread starter Thread starter cj
  • Start date Start date
C

cj

Dim starttime As DateTime
Dim finishtime As DateTime
Dim elapsed As TimeSpan

starttime=now()
some processing
finishtime=now()
elapsedtime=finishtime.subtract(starttime)
messagebox.show(???????????????)

what would I show in the message box if I wanted a message like 1:37 to
indicate it took 1 hr and 37 minutes to run some processing.

I've displayed minutes before but this event could be between a minute
and a few hours.

I guess I could do elapsed.hours & ":" & elapsed.minutes

Is that the best way?
 
Hello cj,

Give elapsedtime.ToString() a shot and see if that's what you want.

Thanks,
Mark
 
TimeSpan.ToString() always use a fixed format to output the string, such as
00:00:02.0001664.

To get the customized format, you could just either use string concat or
use string.Format:

Message.Show(string.Format("{0}:{1}", elapsed.Hours, elapsed.Minutes))



Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
cj,
In addition to the other comments.

I will convert the TimeSpan to a DateTime if I need custom Formatting:


Dim seconds As Integer = 75
Dim elapsed As TimeSpan = TimeSpan.FromSeconds(seconds)
elapsed = finishtime.subtract(starttime)

Dim value As DateTime = DateTime.MinValue.Add(elapsed)
Dim s As String = value.ToString("mm:ss")
messagebox.show(???????????????)
 
Back
Top