• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to convert hours,minutes,seconds to seconds

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I need to convert a time format which is in hh:mm:ss to seconds. please assist me to do this.

Thanks
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

Can you show us what you've tried so far?

best of luck!
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

thanks.I have tried this and got the output


But, What i need is ,I have to get the difference between two values of time like"01:00:00" and "01:20:00". Is it possible to directly subtract these values or i have to convert it into seconds and then only i can able to get the difference?
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

preethi Ayyappan wrote: . . . Is it possible to directly subtract these values . . . ?

You tell us. Write down on a sheet of paper how you would intend to subtract two times. Remember you can only subtract numbers; you cannot "subtract" strings.
Can you create a Time class and subtract hours minutes seconds, or can you only subtract seconds. When you work out how to do it on paper, you will see how to do it in code.

By the way: the names of your variables, h, h1 add temp are not at all informative. Imagine coming back to that code in 6 months are having to work out what "h" means.
 
reply
    Bookmark Topic Watch Topic
  • New Topic