سؤال

how to convert negative seconds to hours minutes, I try this

$todo_tm = -900;
echo gmdate("H:i", $todo_tm);

the output is,

23:45

my expectation is,

-00:15

how to achieve this, any suggestion.

هل كانت مفيدة؟

المحلول

Try with:

$todo_tm = -900;
$time    = gmdate("H:i", abs($todo_tm));

if ($todo_tm < 0) {
    $time = '-' . $time;
}

نصائح أخرى

Use abs to convert in absolute value, then use gmdate().

$todo_tm = abs(-900);
echo gmdate("H:i", $todo_tm);
// Output : 00:15
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top