473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to convert this timespan

Hello,
I want to convert the timespan (1.12:25:23) to 1day 12hour 25min 23sec, how
to do it? thank you.
Sep 27 '08 #1
2 7321
Hello YXQ,

That format you provided is not a timespan, but seems to be a custom
string format. Therefore, the information has to be "cut" out of the
string. If it was just a TimeSpan value (in a timespan variable), then
you could just use the "Days", "Hours", "Minutes" and "Seconds"
properties of the timespan variable to get your result.

To deal with a string in the specified format, you could use this method:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
MsgBox(Convert("1.12:25:23"))
End Sub

Private Function Convert(ByVal TimeSpanString As String) As String
Dim retVal As String
Dim posi As Integer, t As Integer
Dim iTSS As String, iDays As String, iSplit() As String

iTSS = Trim(TimeSpanString)
posi = InStr(TimeSpanString, ".")

If posi 0 Then
iDays = Strings.Left(iTSS, posi - 1)
iTSS = Strings.Right(iTSS, iTSS.Length - posi)
Else
iDays = 0
End If

iSplit = Split(iTSS, ":")

retVal = iDays & "day "

For t = 0 To UBound(iSplit)

If t 2 Then
Exit For 'Just in case the string is longer
End If

retVal &= iSplit(t)
Select Case t
Case 0
retVal &= "hour "

Case 1
retVal &= "min "

Case 2
retVal &= "sec"
End Select
Next

Return retVal
End Function

Best regards,

Martin
On 27.09.2008 10:01, YXQ wrote:
Hello,
I want to convert the timespan (1.12:25:23) to 1day 12hour 25min 23sec, how
to do it? thank you.
Sep 27 '08 #2
Have you tried TimeSpan.Parse?

Dim s As String = "1.12:25:23"
Dim time As TimeSpan = TimeSpan.Parse(s)

Alternatively you can use TimeSpan.TryParse.

Dim s As String = "1.12:25:23"
Dim time As TimeSpan
If TimeSpan.TryParse(s, time) Then
' Its a valid time span
End If
--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"YXQ" <YX*@discussions.microsoft.comwrote in message
news:B5**********************************@microsof t.com...
Hello,
I want to convert the timespan (1.12:25:23) to 1day 12hour 25min 23sec,
how
to do it? thank you.
Oct 19 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris | last post by:
Hello, How can i convert a C++ CTime (4 bytes) into a C# DateTime ? (my CTime is read in a file). Thanks, -- Chris
3
by: glenn h | last post by:
I have i time in Integer = 37825 , how can I convert it in C# to Timeformat = 10:30:25 Glenn
0
by: Harry Haller | last post by:
The context is shown below in the getGames() method. I get errors on these lines: dtGames.Rows = (TimeSpan)dtGames.Rows; dtGames.Rows = (DayOfWeek)dtGames.Rows; because the playDate column...
6
by: Mike | last post by:
I'm getting my data from my database in seconds, 3600, how can i convert that to time such as 1:00 pm?
14
by: Michael Barrido | last post by:
I have this for example: Dim iSeconds as int32 = 3600 '3600 seconds is one hour How do i convert it to "01:00:00" ? Please help. Thanks in advance!
7
by: WorldIsEnding | last post by:
Hey, Im having trouble with converting a Numeric value (such as a single digit number like 1 or 5) into a time format. I need to convert a number entered into a variable into Hours on the...
8
by: Praveen | last post by:
how to convert DateTime.UtcNow.ticks to Milliseconds
3
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
Hello - I have various times formatted like 00:00:00, so for example, 01:32:05 would be one thirty-two with five milliseconds. I need to convert this into seconds (an integer). First of...
1
by: John A Grandy | last post by:
How to generically convert an object to a target type ? So .... I'm looking for something like : DateTime value = new DateTime( 2008, 9, 18, 8, 35, 31, 10 ); System.Type targetType =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.