note 109049 deleted from function.strtotime by derick

From: Date: Sun, 14 Dec 2014 11:31:20 +0000
Subject: note 109049 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201157@lists.php.net to get a copy of this message
Note Submitter: elad dot yosifon at gmail dot com ---- 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); ?>

« previous php.notes (#201157) next »