idoodler
idoodler

Reputation: 3545

How to calculate in Ruby?

I am trying to calculate with the uptime-seconds from my Raspberry Pi. I need to get the hours and minutes. I use

upSeconds = `/usr/bin/cut -d. -f1 /proc/uptime`

to get the seconds now I have to calculate to get to the hours and minutes, how do I calculate with Ruby, from Objective C I know it should work with /, *, +, - but how do I use this?

Upvotes: 0

Views: 127

Answers (1)

Salem
Salem

Reputation: 12996

I have never worked with ObjC but probably the operators are exactly the same:

upSeconds = `/usr/bin/cut -d. -f1 /proc/uptime`

seconds = upSeconds.chomp.to_i # remove "\n" at the end and pass to int (ms lost)
hours = seconds / (60*60)
minutes = (seconds - (hours * 60 * 60)) / 60

Upvotes: 1

Related Questions