Pregunta

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?

¿Fue útil?

Solución

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top