Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert time in seconds in ruby

I've got time 2014-01-01 06:31:00 UTC.

from above time format I need to extract 06:31:00 in seconds except year:month:date

i.e 2014-01-01 06:31:00 should return 6*60*60+31*60=23460 seconds,

what is the best approach for this

like image 242
omr3421 Avatar asked Mar 29 '26 23:03

omr3421


1 Answers

Rails provides Time#seconds_since_midnight:

time = Time.parse("2014-01-01 06:31:00 UTC")

time.seconds_since_midnight
#=> 23460.0
like image 114
Stefan Avatar answered Apr 02 '26 06:04

Stefan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!