Wednesday 15 February 2012

Ruby: Time difference in percentage? -


How do I, for example, know that between 4:00 and 8pm, at 6:00 p.m. 50%? Or is it 50% between 12 o'clock Wednesday 12 and Tuesday 12am?

Convert from seconds to seconds, calculate the difference between your desired time and the first time in seconds, Calculate the whole duration fraction, and then multiply by 100%

12 AM = 0

12 PM = 43200 seconds (of day)

Your desired time = 3 AM = 10800 second of the day

Total time duration = 43200 - 0 = 43200 seconds

Time difference of your desired time from the first time = 10800 - 0 = 10800 seconds

Fraction = 10800/43200 = 0.25

percent = 0.25 * 100% = 25%

(Sorry Ruby does not know, but its idea .)


No comments:

Post a Comment