Work out the percentage of the day that has elapsed

前端 未结 5 582
深忆病人
深忆病人 2021-01-12 10:10

Slightly strange question, but hopefully someone can help.

In essence, if the time was 12pm the the elapsed percentage would be 50%, 6am would be 25% and 16pm would

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 10:46

    gettimeofday(true) returns the number of seconds elapsed since midnight as a float (I think), so you want: gettimeofday(true)/(60*60*24). Multiply by 100 to get a percentage.

    EDIT: Actually, gettimeofday returns the number of seconds elapsed since the start of the epoch, so you need to subtract midnight:

    $midnight = strtotime('00:00');
    $epochseconds = gettimeofday(true);
    $timeofdayseconds = $epochseconds - $midnight;
    $timepercent = $timeofdayseconds/(60*60*24)*100;
    

提交回复
热议问题