如何在两个时间戳之间找到百分比

Sim*_*sen 2 php timestamp progress-bar

大家好:)我怎样才能获得unix时间戳之间的百分比(我需要将它用于我的进度条)

如果我有例如1303248948和1303252200.我怎么能找出100%百分比的百分比.

因此,当第一个时间戳接近第二个时间戳时,我的进度条会不断改变宽度.

所以它将是:width ="1%"和width ="2%"等等,直到它达到100%的宽度.

希望可以有人帮帮我!;-)

Chr*_*ian 17

实际上,你需要3个时间戳:

起始邮票,当前邮票(进度),完成邮票

我假设当前的邮票是当前的time().在这种情况下;

$begin= strtotime('-2 weeks');
$now = time();
$end = strtotime('+2 weeks');

$percent = ($now-$begin) / ($end-$begin) * 100;
Run Code Online (Sandbox Code Playgroud)

注意:在上面的例子中,$percent应该是50%.