문제

I am receiving the following value from a database which is a millsecond (microtime) value

1369057622.4679

I would like to output this in PHP to be

3 Day's ago

Essentially reading the milliseconds value and converting it to a relative date string, can anyone suggest an easy method to do this.

도움이 되었습니까?

해결책

You may do the following:

$input = 1369057622.4679;

$diff = floor(($input-time())/86400); // calculating the difference

$result = abs($diff) . (abs($diff)==1 ? ' day ':' days ') . ($diff<=0 ? 'ago':'ahead'); // making the result.
echo $result; // output: 1 day ago
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top