1 Attachment(s)
[RESOLVED] Conversion of hh:mm:ss to seconds
Currently, I have 4 textboxes displaying hh , mm, ss and ms.
I am required to convert only the Seconds, Minutes, and Hours and display it into another textbox (see attached doc for diagram).
I've got a brief idea that for the hours, i'm required to multiply by 3600, and as for the minutes, multiply by 60. Am i correct? Please correct me if i'm wrong. But as for the actual coding of conversion and how to display it into another textbox, i'm not sure how to do so.
As i'm very new to vb, therefore I would like to seek guidance on how can i do so. Thanks in advance for the help.
Re: Conversion of hh:mm:ss to seconds
I don't really understand the post itself but I do understand the title :). I had a similiar problem a couple of months ago. This is what I use to get the number of seconds of a timespan.
vb Code:
Private Function GetSeconds(ByVal timestamp As DateTime) As Integer
Dim timespan As TimeSpan = Now - timestamp
Return ((timespan.Hours * 60) + timespan.Minutes) * 60 + timespan.Seconds
End Function
Very simple... Just turn hours to minutes (timespan.hours * 60) add this to the timespan.minutes. Turn all the minutes into seconds (* 60) and add the other seconds.
Hope that helps.
Re: Conversion of hh:mm:ss to seconds
Hello Gonzalioz , thank you for your time in answering my enquiries. Will try your method on my project now. Once again, thanks alot for your help! =)
Re: Conversion of hh:mm:ss to seconds
This works with much less code. :)
Code:
timespan.TotalSeconds
Re: Conversion of hh:mm:ss to seconds
Quote:
Originally Posted by
Campion
This works with much less code. :)
Code:
timespan.TotalSeconds
Thanks! Didn't know about that. You can't find things like that on the internet :D. I wish I had a proper teacher that passed on some information once in a while.
Re: Conversion of hh:mm:ss to seconds
Quote:
Originally Posted by
gonzalioz
Thanks! Didn't know about that. You can't find things like that on the internet :D. I wish I had a proper teacher that passed on some information once in a while.
Actually, you can. Every class the .NET framework is discussed in depth on MSDN.
Re: Conversion of hh:mm:ss to seconds
Quote:
Originally Posted by
Campion
Actually, you can. Every class the .NET framework is discussed in depth on MSDN.
If I didn't know milkbottles existed, I wouldn't type in milkbottles in google to find them right? You can't search for something you don't even know it exists. You have to come across it by accident. Which is what just happened :). And that's alright, but it would be much more effective if that kind of information was passed on by teachers, that's what I pay them for. That's what a study is all about. At least... at higher levels it is. Get a load of information and learn techniques in 3-4 years time and refine your skills after your study in the real world.
Re: Conversion of hh:mm:ss to seconds
Quote:
Originally Posted by
gonzalioz
If I didn't know milkbottles existed, I wouldn't type in milkbottles in google to find them right? You can't search for something you don't even know it exists.
You can, however, search using ideas that relate to a milk bottle.
Googling ".Net total number of seconds" doesn't retrieve very direct information, but it's a start. However, googling ".Net total seconds" takes you exactly to what you want to know:
The article on the TotalSeconds property of the Timespan structure.
I can't comment about your teacher(s), as it was probably not in their lesson plan, but if you use Visual Studio to any degree, you've used MSDN in some way. Since MSDN is built specifically for developers, it should be your first resource. Although, I have to admit, sometimes MSDN is confusing, so googling is a better bet.
Re: Conversion of hh:mm:ss to seconds
Quote:
Originally Posted by
Campion
You can, however, search using ideas that relate to a milk bottle.
Googling ".Net total number of seconds" doesn't retrieve very direct information, but it's a start. However, googling ".Net total seconds" takes you exactly to what you want to know:
The article on the TotalSeconds property of the Timespan structure.
I can't comment about your teacher(s), as it was probably not in their lesson plan, but if you use Visual Studio to any degree, you've used MSDN in some way. Since MSDN is built specifically for developers, it should be your first resource. Although, I have to admit, sometimes MSDN is confusing, so googling is a better bet.
Haha yeah, sometimes I google for something and use MSDN as a keyword. Like, 'MSDN String Format' for example. The search engine of msdn is so bad, crappy Bing.
Re: Conversion of hh:mm:ss to seconds
Quote:
Originally Posted by
gonzalioz
Haha yeah, sometimes I google for something and use MSDN as a keyword. Like, 'MSDN String Format' for example. The search engine of msdn is so bad, crappy Bing.
If you just want to search MSDN from google you can use:
site:msdn.microsoft.com number of seconds
Quote:
, but it would be much more effective if that kind of information was passed on by teachers, that's what I pay them for. That's what a study is all about.
I have to disagree with you on this. Do you really want your teachers teaching you something as specific as that? If you are studying programming or computer science, you shouldn't be focusing on learning all of the details of a specific language, as languages come and go. You need to understand the concepts that apply across the board. If you want to learn that there is a TotalSeconds property of the TimeSpan, that is what intellisense and MSDN are for.