1--TEST-- 2date_create_from_format() and date_parse_from_format(). 3--FILE-- 4<?php 5date_default_timezone_set('Europe/Oslo'); 6$formats = array( DATE_ATOM, DATE_COOKIE, DATE_ISO8601, DATE_RFC822, 7 DATE_RFC850, DATE_RFC1036, DATE_RFC1123, DATE_RFC2822, DATE_RFC3339, 8 DATE_RSS, DATE_W3C ); 9 10foreach( $formats as $format ) 11{ 12 $date = new DateTime( "2008-07-08T22:14:12+02:00" ); 13 $formatted = $date->format( $format ) ; 14 $date2 = date_create_from_format( $format, $formatted ); 15 var_dump( $format, $formatted, $date2 ); 16 echo "\n"; 17 if ( $date2 === false ) 18 { 19 var_dump(date_parse_from_format( $format, $formatted ) ); 20 } 21} 22?> 23--EXPECT-- 24string(13) "Y-m-d\TH:i:sP" 25string(25) "2008-07-08T22:14:12+02:00" 26object(DateTime)#2 (3) { 27 ["date"]=> 28 string(26) "2008-07-08 22:14:12.000000" 29 ["timezone_type"]=> 30 int(1) 31 ["timezone"]=> 32 string(6) "+02:00" 33} 34 35string(16) "l, d-M-Y H:i:s T" 36string(38) "Tuesday, 08-Jul-2008 22:14:12 GMT+0200" 37object(DateTime)#1 (3) { 38 ["date"]=> 39 string(26) "2008-07-08 22:14:12.000000" 40 ["timezone_type"]=> 41 int(1) 42 ["timezone"]=> 43 string(6) "+02:00" 44} 45 46string(13) "Y-m-d\TH:i:sO" 47string(24) "2008-07-08T22:14:12+0200" 48object(DateTime)#3 (3) { 49 ["date"]=> 50 string(26) "2008-07-08 22:14:12.000000" 51 ["timezone_type"]=> 52 int(1) 53 ["timezone"]=> 54 string(6) "+02:00" 55} 56 57string(16) "D, d M y H:i:s O" 58string(29) "Tue, 08 Jul 08 22:14:12 +0200" 59object(DateTime)#2 (3) { 60 ["date"]=> 61 string(26) "2008-07-08 22:14:12.000000" 62 ["timezone_type"]=> 63 int(1) 64 ["timezone"]=> 65 string(6) "+02:00" 66} 67 68string(16) "l, d-M-y H:i:s T" 69string(36) "Tuesday, 08-Jul-08 22:14:12 GMT+0200" 70object(DateTime)#1 (3) { 71 ["date"]=> 72 string(26) "2008-07-08 22:14:12.000000" 73 ["timezone_type"]=> 74 int(1) 75 ["timezone"]=> 76 string(6) "+02:00" 77} 78 79string(16) "D, d M y H:i:s O" 80string(29) "Tue, 08 Jul 08 22:14:12 +0200" 81object(DateTime)#3 (3) { 82 ["date"]=> 83 string(26) "2008-07-08 22:14:12.000000" 84 ["timezone_type"]=> 85 int(1) 86 ["timezone"]=> 87 string(6) "+02:00" 88} 89 90string(16) "D, d M Y H:i:s O" 91string(31) "Tue, 08 Jul 2008 22:14:12 +0200" 92object(DateTime)#2 (3) { 93 ["date"]=> 94 string(26) "2008-07-08 22:14:12.000000" 95 ["timezone_type"]=> 96 int(1) 97 ["timezone"]=> 98 string(6) "+02:00" 99} 100 101string(16) "D, d M Y H:i:s O" 102string(31) "Tue, 08 Jul 2008 22:14:12 +0200" 103object(DateTime)#1 (3) { 104 ["date"]=> 105 string(26) "2008-07-08 22:14:12.000000" 106 ["timezone_type"]=> 107 int(1) 108 ["timezone"]=> 109 string(6) "+02:00" 110} 111 112string(13) "Y-m-d\TH:i:sP" 113string(25) "2008-07-08T22:14:12+02:00" 114object(DateTime)#3 (3) { 115 ["date"]=> 116 string(26) "2008-07-08 22:14:12.000000" 117 ["timezone_type"]=> 118 int(1) 119 ["timezone"]=> 120 string(6) "+02:00" 121} 122 123string(16) "D, d M Y H:i:s O" 124string(31) "Tue, 08 Jul 2008 22:14:12 +0200" 125object(DateTime)#2 (3) { 126 ["date"]=> 127 string(26) "2008-07-08 22:14:12.000000" 128 ["timezone_type"]=> 129 int(1) 130 ["timezone"]=> 131 string(6) "+02:00" 132} 133 134string(13) "Y-m-d\TH:i:sP" 135string(25) "2008-07-08T22:14:12+02:00" 136object(DateTime)#1 (3) { 137 ["date"]=> 138 string(26) "2008-07-08 22:14:12.000000" 139 ["timezone_type"]=> 140 int(1) 141 ["timezone"]=> 142 string(6) "+02:00" 143} 144