note 109049 added to function.strtotime

From: Date: Fri, 15 Jun 2012 20:12:55 +0000
Subject: note 109049 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-188638@lists.php.net to get a copy of this message
This example shows common methods to get a timestamp from $year,$month,$day variables. strtotime() with implode() seems to be the fastest way (performance wise..) <?php function logTime($start,$end,$functionName){ echo "$functionName() = ".(float)($end-$start)*(60*60)."<br>"; } $day = '01'; $month = '01'; $year = '2000'; $time = array(); $timestamps = array(); $time[] = array(microtime(true),'start'); $timestamps[] = mktime(0,0,0,$month,$day,$year); $time[] = array(microtime(true),'mktime'); $timestamps[] = strtotime($year.'-'.$month.'-'.$day); $time[] = array(microtime(true),'strtotime'); $timestamps[] = strtotime(implode('-', array($year, $month, $day))); $time[] = array(microtime(true),'strtotime_Array'); $timestamps[] = date_create_from_format('!Y-m-d', $year.'-'.$month.'-'.$day)->getTimestamp(); $time[] = array(microtime(true),'date_create_from_format'); $timestamps[] = date_create_from_format('!Y-m-d', implode('-', array($year, $month, $day)))->getTimestamp(); $time[] = array(microtime(true),'date_create_from_format_Array'); $timestamps[] = DateTime::createFromFormat('!Y-m-d', $year.'-'.$month.'-'.$day)->getTimestamp(); $time[] = array(microtime(true),'DateTime'); $timestamps[] = DateTime::createFromFormat('!Y-m-d', implode('-', array($year, $month, $day)))->getTimestamp(); $time[] = array(microtime(true),'DateTime_Array'); foreach ($time as $key=>$value) { if(end($time) == $value){}else{ logTime($value[0],$time[$key+1][0],$time[$key+1][1]); } } // just to show that all timestamps are correct var_dump($timestamps); ---- Server IP: 69.147.83.197 Probable Submitter: 109.65.166.226 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/109049 Del: integrated -- https://master.php.net/note/delete/109049/integrated Del: useless -- https://master.php.net/note/delete/109049/useless Del: bad code -- https://master.php.net/note/delete/109049/bad+code Del: spam -- https://master.php.net/note/delete/109049/spam Del: non-english -- https://master.php.net/note/delete/109049/non-english Del: in docs -- https://master.php.net/note/delete/109049/in+docs Del: other reasons-- https://master.php.net/note/delete/109049 Reject -- https://master.php.net/note/reject/109049 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188638) next »