• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to convert hours,minutes,seconds to seconds  RSS feed

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 56600
172
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!