Guest User

Untitled

a guest
Oct 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. require 'date'
  2.  
  3. start_time = "2012-03-02 14:46:21"
  4. today_date = Time.now.strftime("%Y-%d-%m %H:%M;%S")
  5. end_time = "2017-04-02 14:46:21"
  6.  
  7. st, nt, et = [start_time, now, end_time].map do |t|
  8. # convert to unix timestamp, as float
  9. DateTime.parse(t).strftime('%s').to_f
  10. end
  11. result = (nt - st) / (et - st) # assumes start < today < end
Add Comment
Please, Sign In to add comment