note 75913 added to function.strftime

From: Date: Thu, 21 Jun 2007 12:03:07 +0000
Subject: note 75913 added to function.strftime
Groups: php.notes 
Request: Send a blank email to php-notes+get-127856@lists.php.net to get a copy of this message
This little function allows you to provide a reasonably human readable string and convert to a timestamp - see example in comments below. I find it far more useful than having to remember all the '%' modifiers. Am also well aware of its failings but it works in a lot of the real life situations I've come across. <?php function AmazingStringFromTime($str, $nTimestamp = null) { // This function reads a human readable string representation of dates. e.g. // DD MM YYYY => 01 07 1978 // DDD D MMM YY => Mon 1 Jul 78 $arrPairs = array( "DDDD" => "%A", "DDD" => "%a", "DD" => "%d", "D" => "%e", // has leading space: ' 1', ' 2', etc for single digit days "MMMM" => "%B", "MMM" => "%b", "MM" => "%m", "YYYY" => "%Y", "YY" => "%y", "HH" => "%H", "hh" => "%I", "mm" => "%M", "ss" => "%S", ); $str = str_replace(array_keys($arrPairs), array_values($arrPairs), $str); return strftime($str, $nTimestamp); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 217.34.41.143 ---- Manual Page -- http://www.php.net/manual/en/function.strftime.php Edit -- https://master.php.net/note/edit/75913 Del: integrated -- https://master.php.net/note/delete/75913/integrated Del: useless -- https://master.php.net/note/delete/75913/useless Del: bad code -- https://master.php.net/note/delete/75913/bad+code Del: spam -- https://master.php.net/note/delete/75913/spam Del: non-english -- https://master.php.net/note/delete/75913/non-english Del: in docs -- https://master.php.net/note/delete/75913/in+docs Del: other reasons-- https://master.php.net/note/delete/75913 Reject -- https://master.php.net/note/reject/75913 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127856) next »