|
-
Aug 22nd, 2007, 11:50 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Minutes to Hour & minutes
Hi
How can I convert the total minutes into hour minutes.
ex:
Total minutes : 209
I want it should display : 3 hours 29 minutes
thanks
asm
-
Aug 23rd, 2007, 12:06 AM
#2
Re: Minutes to Hour & minutes
vb.net Code:
Dim time As TimeSpan = TimeSpan.FromMinutes(209)
MessageBox.Show(String.Format("{0} hours {1} minutes", _
time.Hours, _
time.Minutes))
Note that that will only be correct if the total time is less than 24 hours. If you want to handle times greater than that then do this:
vb.net Code:
Dim time As TimeSpan = TimeSpan.FromMinutes(209)
MessageBox.Show(String.Format("{0} hours {1} minutes", _
Math.Floor(time.TotalHours), _
time.Minutes))
-
Aug 23rd, 2007, 12:19 AM
#3
Thread Starter
Hyperactive Member
Re: Minutes to Hour & minutes
thanks for your quick help
-
Aug 23rd, 2007, 12:35 AM
#4
Thread Starter
Hyperactive Member
Re: Minutes to Hour & minutes
How can I display the total minutes - get from textbox1
display in textbox2 with hour minutes
vb Code:
Dim TotalMinutes As Double
TotalMinutes = Val(TextBox1.Text)
Dim ShowTime As TimeSpan = TimeSpan.FromMinutes(TotalMinutes)
TextBox2.Text = ShowTime.Hours + ShowTime.Minutes
MessageBox.Show(String.Format("{0} hours {1} minutes", ShowTime.Hours, ShowTime.Minutes))
-
Aug 23rd, 2007, 12:44 AM
#5
Re: Minutes to Hour & minutes
I have no idea what you just asked for.
-
Aug 23rd, 2007, 12:55 AM
#6
Fanatic Member
Re: Minutes to Hour & minutes
Last edited by newprogram; Aug 23rd, 2007 at 12:59 AM.
Live life to the fullest!!
-
Aug 24th, 2007, 12:21 AM
#7
Thread Starter
Hyperactive Member
Re: Minutes to Hour & minutes
it work but it show in message box,
but i want it will show in textbox like 3:29
thanks
-
Aug 24th, 2007, 12:55 AM
#8
Re: Minutes to Hour & minutes
You really should apply some thought to the problem before asking for help. You display a string in a MessageBox like this:
vb.net Code:
MessageBox.Show(myString)
You display a string in a TextBox like this:
vb.net Code:
myTextBox.Text = myString
I've shown you how to create the string you want and I used the MessageBox to show it as an example. If you want to show the string in a TextBox instead then by all means do so. You already know how to create the string so you can do whatever you want with it.
Last edited by jmcilhinney; Aug 24th, 2007 at 01:04 AM.
-
Aug 24th, 2007, 01:07 AM
#9
Thread Starter
Hyperactive Member
Re: Minutes to Hour & minutes
thanks...
I achive the result using code:
vb Code:
TextBox2.Text = ShowTime.Hours.ToString + ":" + ShowTime.Minutes.ToString
-
Aug 24th, 2007, 01:18 AM
#10
Re: [RESOLVED] Minutes to Hour & minutes
Why not use the String.Format method like I showed you:
vb.net Code:
TextBox2.Text = String.Format("{0}:{1:00}", ShowTime.Hours, ShowTime.Minutes))
Note that I've also specified that the minutes be displayed with two digits with "{1:00}". Using your code if the minutes are not double figures you'd end up with a string like "3:9" instead of "3:09". That said, you could still use code like yours to get double-digit minutes if you use ShowTime.Minutes.ToString("00").
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|