Saniyeden İngilizce Saati - CSS Hileleri

İçindekiler

Saniyeye dönüştürülmesini istediğiniz zamanı İngilizce olarak yazmanız yeterlidir (örneğin “1 saat 30 dakika”) ve saniye tam sayıya dönüştürülecektir (ör. 5400). Baylor Rae'ye teşekkürler.

function time2seconds($time) ( preg_match_all('/(\d+ (a-z)+)/', $time, $matches); $matches = $matches(0); $formats = array(); foreach ($matches as $format) ( preg_match('/(\d+)\s?((a-z)+)/', $format, $f); $time = $f(1); $type = $f(2); $formats($type) = $time; ) $output = array( 'years' => 0, 'months' => 0, 'days' => 0, 'hours' => 0, 'minutes' => 0, 'seconds' => 0 ); foreach ($formats as $format => $time) ( if( $time == 0 ) continue; switch ($format) ( case 'year' : case 'years' : $output('years') = $time * 12 * 30 * 24 * 60 * 60; break; case 'month' : case 'months' : $output('months') = $time * 30 * 24 * 60 * 60; break; case 'day' : case 'days' : $output('days') = $time * 24 * 60 * 60; break; case 'hour' : case 'hours' : $output('hours') = $time * 60 * 60; break; case 'minute' : case 'minutes' : $output('minutes') = $time * 60; break; case 'second' : case 'seconds' : $output('seconds') = $time; break; ) ) return $output('years') + $output('months') + $output('days') + $output('hours') + $output('minutes') + $output('seconds'); )

Basit Kullanım

Form, "zamanı" gönderir:

 Time
Test!

"Zaman" ayarlanmışsa, işlevi kullanın ve döndürülen şeyi yankılayın:

if (isset($_POST)) ( echo time2seconds($_POST('time')); )

Ilginç makaleler...