K
K
Konstantin T2014-02-05 09:58:09
PHP
Konstantin T, 2014-02-05 09:58:09

How to easily parse unix_timestamp time beyond 24 hours in PHP?

The time can be 12h and 48h and 123h and it can be written both with minutes and seconds, for example: 72h 38m The strtotime
function does not accept such a format, it just produces a void. Maybe there is some standard way to parse time in unix_timestamp?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2014-02-05
@RooTooZ

$time = '123h 5 m 07s';
if (preg_match('~(\d+)\s*h~', $time, $match)
    $hours = $match[1];
if (preg_match('~(\d+)\s*m~', $time, $match)
    $minutes = $match[1];
if (preg_match('~(\d+)\s*s~', $time, $match)
    $seconds = $match[1];

Only for unix_timestamp, the date and time zone are also needed, this is the number of seconds since 1970-01-01 00:00:00 UTC.

K
Kirill Firsov, 2014-02-05
@Isis

If you solve your problem with regular expressions, then you have 2 problems.

K
Kirill Platonov, 2014-02-05
@kirillplatonov

Parse your data using regular expressions for seconds, minutes, and hours in s/m/h respectively. After that collect the timestamp with mktime .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question