Results 1 to 10 of 10

Thread: [RESOLVED] Conversion of hh:mm:ss to seconds

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Resolved [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.
    Attached Files Attached Files

  2. #2
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    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:
    1. Private Function GetSeconds(ByVal timestamp As DateTime) As Integer
    2.  
    3.         Dim timespan As TimeSpan = Now - timestamp
    4.         Return ((timespan.Hours * 60) + timespan.Minutes) * 60 + timespan.Seconds
    5.  
    6.     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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    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! =)

  4. #4
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Conversion of hh:mm:ss to seconds

    This works with much less code.

    Code:
    timespan.TotalSeconds
    From my burrow, 2 feet under.

  5. #5
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Re: Conversion of hh:mm:ss to seconds

    Quote Originally Posted by Campion View Post
    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 . I wish I had a proper teacher that passed on some information once in a while.

  6. #6
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Conversion of hh:mm:ss to seconds

    Quote Originally Posted by gonzalioz View Post
    Thanks! Didn't know about that. You can't find things like that on the internet . 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.
    From my burrow, 2 feet under.

  7. #7
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Re: Conversion of hh:mm:ss to seconds

    Quote Originally Posted by Campion View Post
    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.

  8. #8
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Conversion of hh:mm:ss to seconds

    Quote Originally Posted by gonzalioz View Post
    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.
    From my burrow, 2 feet under.

  9. #9
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Re: Conversion of hh:mm:ss to seconds

    Quote Originally Posted by Campion View Post
    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.

  10. #10
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Conversion of hh:mm:ss to seconds

    Quote Originally Posted by gonzalioz View Post
    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

    , 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width