|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-07-01 09:38 UTC] sniper@php.net
[2005-07-01 10:15 UTC] derick@php.net
[2005-07-03 21:15 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
Description: ------------ Getting different output for strftime() and date(), and wondering whether these should be the same. Example code: <?php print "TZ has NOT been set\n"; print "Should strftime==datestr? Strftime seems to assume GMT tStamp.\n"; $input = "10:00:00 AM July 1 2005"; print "input " . $input . "\n"; $tStamp = strtotime($input); print "strftime " . strftime("%r %B%e %Y", $tStamp) . "\n"; print "datestr " . date ("H:i:s A F j Y", $tStamp) . "\n"; print "\nSetting TZ\n"; putenv ("TZ=Australia/Sydney"); $input = "10:00:00 AM July 1 2005"; print "input " . $input . "\n"; $tStamp = strtotime($input); print "strftime " . strftime("%r %B%e %Y", $tStamp) . "\n"; print "datestr " . date ("H:i:s A F j Y", $tStamp) . "\n"; ?> Output: ------------------------------------------------- ludo:~/tmp/php-5.1-dev/strftime-vs-date# ../php5-200507010030/sapi/cli/php ./strftime-vs-date.php TZ has NOT been set Should strftime==datestr? Strftime seems to assume GMT tStamp. input 10:00:00 AM July 1 2005 strftime 08:00:00 PM July 1 2005 datestr 10:00:00 AM July 1 2005 Setting TZ input 10:00:00 AM July 1 2005 strftime 10:00:00 AM July 1 2005 datestr 10:00:00 AM July 1 2005 ludo:~/tmp/php-5.1-dev/strftime-vs-date# ------------------------------------------------- Expected output: ------------------------------------------------- TZ has NOT been set Should strftime==datestr? Strftime seems to assume GMT tStamp. input 10:00:00 AM July 1 2005 strftime 10:00:00 AM July 1 2005 datestr 10:00:00 AM July 1 2005 Setting TZ input 10:00:00 AM July 1 2005 strftime 10:00:00 AM July 1 2005 datestr 10:00:00 AM July 1 2005 ludo:~/tmp/php-5.1-dev/strftime-vs-date# ------------------------------------------------- Note: the "%r" strftime format is described thus: "time in a.m. and p.m. notation". The strftime documentation does not indicate that this is altered by the locale settings (unlike the weekday, month, and so on are). However my locale is English anyway, which is what date() seems to use, and the locale is not adjusted by the above script, so I would anticipate getting the same output between date and strftime.