|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
converting minutes into hrs minsI am returning a value from a db table, which is the number of mins. I need to convert this to hrs mins which I have done using the following code, and also displayed it in my grid: Dim ts As TimeSpan = TimeSpan.FromMinutes(balance) tempItem.Cells(8).Text = (ts.Hours & ":" & ts.Minutes) However I have a problem with the minutes, 8:04 is currently displayed as 8.4, i am using the following code: Dim Minstring As New StringBuilder Dim testLength As Integer = CStr(ts.Minutes).Length If testLength <2 Then Dim tempMin As String = "0" tempMin &= ts.Minutes Minstring.Append(tempMin) Else Minstring.Append(ts.Minutes) End If !!still displays 8.4, yet this works in a similar project I have when used exclusively on dates!! However I also have negative numbers for this value which when displayed looks like the following: -1:-23 instead of - 1:23 Does anyone have any ideas on how to remove the " - " sign from mins, and also put a " 0 " infront of the 4 in 8:4 Any help would be much appreciated, Cheers, Simon Hello,
I would write a simple time formatting routine like this: Private Function FormatTime(ByVal ts As TimeSpan) As String Return String.Format("{0}:{1:D2}", ts.Hours, ts.Duration.Minutes) End Function Kelly si_owen wrote: Show quoteHide quote > Hi folks, > > I am returning a value from a db table, which is the number of mins. I > need to convert this to hrs mins which I have done using the following > code, and also displayed it in my grid: > > Dim ts As TimeSpan = TimeSpan.FromMinutes(balance) > tempItem.Cells(8).Text = (ts.Hours & ":" & ts.Minutes) > > However I have a problem with the minutes, 8:04 is currently displayed > as 8.4, i am using the following code: > > Dim Minstring As New StringBuilder > Dim testLength As Integer = CStr(ts.Minutes).Length > > If testLength <2 Then > Dim tempMin As String = "0" > tempMin &= ts.Minutes > Minstring.Append(tempMin) > Else > Minstring.Append(ts.Minutes) > > End If > > !!still displays 8.4, yet this works in a similar project I have when > used exclusively on dates!! > > However I also have negative numbers for this value which when > displayed looks like the following: > > -1:-23 instead of - 1:23 > > Does anyone have any ideas on how to remove the " - " sign from mins, > and also put a " 0 " infront of the 4 in 8:4 > > > Any help would be much appreciated, > > Cheers, > > Simon > si_owen wrote:
> sorted out the 0 in 8:04 Use the Math.Abs() function to convert the negative value to a positive one. > > just the - sign now > > so -7:-34 shud be -7:34 Wrap this around the code you're using to extract the minutes from your TimeSpan and hopefully that'll sort this problem out for you. -- (O)enone
Retrieving Values from Dynamically Created Controls
Dynamically load a form Raising an event from a user control Changing file name Determine if app fails... Detect Multiple Keystrokes? Inherited form Name from Base Borderless Form VS2005 Upgrade Question regular expression used to conver to upper case |
|||||||||||||||||||||||