| 1 |
lars |
1 |
<?php
|
|
|
2 |
//
|
|
|
3 |
//
|
|
|
4 |
//
|
|
|
5 |
|
|
|
6 |
//ini_set('include_path',realpath(dirname(__FILE__).'/../../../').':'.realpath(dirname(__FILE__).'/../../../../includes').':'.ini_get('include_path'));
|
|
|
7 |
//ini_set('error_reporting',E_ALL);
|
|
|
8 |
ini_set('include_path',ini_get('include_path').':../..');
|
|
|
9 |
|
|
|
10 |
print "You can set the locale by giving a GET-param i.e. '?lang=fr_FR'<br><br>";
|
|
|
11 |
|
|
|
12 |
require_once 'I18N/DateTime.php';
|
|
|
13 |
|
|
|
14 |
if (@$_REQUEST['lang']) {
|
|
|
15 |
$lang = $_REQUEST['lang'];
|
|
|
16 |
} else {
|
|
|
17 |
$lang = 'en_US';
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
echo 'require_once \'I18N/DateTime.php\';<br>';
|
|
|
21 |
echo '$dateTime = new I18N_DateTime( \''.$lang.'\' );<br><br>';
|
|
|
22 |
$dateTime =& I18N_DateTime::singleton($lang);
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
//
|
|
|
26 |
// very simple examples, to get the date and/or time for now
|
|
|
27 |
//
|
|
|
28 |
myPrint('<h1>simple Examples</h1>');
|
|
|
29 |
|
|
|
30 |
//
|
|
|
31 |
// get the time now in format DEFAULT
|
|
|
32 |
//
|
|
|
33 |
myPrint( '$dateTime->format() . . . '. $dateTime->format() );
|
|
|
34 |
myPrint( '$dateTime->formatShort() . . . '. $dateTime->formatShort() );
|
|
|
35 |
myPrint( '$dateTime->formatMedium() . . . '. $dateTime->formatMedium() );
|
|
|
36 |
myPrint( '$dateTime->formatLong() . . . '. $dateTime->formatLong() );
|
|
|
37 |
myPrint( '$dateTime->formatFull() . . . '. $dateTime->formatFull() );
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
echo '<br><br>';
|
|
|
41 |
myPrint( '$dateTime->formatTime() . . . '. $dateTime->formatTime() );
|
|
|
42 |
myPrint( '$dateTime->formatTimeShort() . . . '. $dateTime->formatTimeShort() );
|
|
|
43 |
myPrint( '$dateTime->formatTimeMedium() . . . '. $dateTime->formatTimeMedium() );
|
|
|
44 |
myPrint( '$dateTime->formatTimeLong() . . . '. $dateTime->formatTimeLong() );
|
|
|
45 |
myPrint( '$dateTime->formatTimeFull() . . . '. $dateTime->formatTimeFull() );
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
echo '<br><br>';
|
|
|
49 |
myPrint( '$dateTime->formatDate() . . . '. $dateTime->formatDate() );
|
|
|
50 |
myPrint( '$dateTime->formatDateShort() . . . '. $dateTime->formatDateShort() );
|
|
|
51 |
myPrint( '$dateTime->formatDateMedium() . . . '. $dateTime->formatDateMedium() );
|
|
|
52 |
myPrint( '$dateTime->formatDateLong() . . . '. $dateTime->formatDateLong() );
|
|
|
53 |
myPrint( '$dateTime->formatDateFull() . . . '. $dateTime->formatDateFull() );
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
////////////////////////////////////////////
|
|
|
58 |
//
|
|
|
59 |
// DATE and TIME
|
|
|
60 |
//
|
|
|
61 |
//
|
|
|
62 |
|
|
|
63 |
myPrint('<h1>DATE and TIME</h1>');
|
|
|
64 |
|
|
|
65 |
//
|
|
|
66 |
// get the time now in format DEFAULT
|
|
|
67 |
//
|
|
|
68 |
myPrint( $dateTime->format() );
|
|
|
69 |
|
|
|
70 |
//
|
|
|
71 |
// get the time now in format FULL
|
|
|
72 |
//
|
|
|
73 |
myPrint( $dateTime->format( mktime(0,0,0,1,12,12) , I18N_DATETIME_FULL ) );
|
|
|
74 |
// or like this
|
|
|
75 |
$dateTime->setFormat( I18N_DATETIME_FULL );
|
|
|
76 |
myPrint( $dateTime->format() );
|
|
|
77 |
|
|
|
78 |
// all possible formats
|
|
|
79 |
myPrint( $dateTime->format( time() , I18N_DATETIME_SHORT ) );
|
|
|
80 |
myPrint( $dateTime->format( time() , I18N_DATETIME_MEDIUM ) );
|
|
|
81 |
myPrint( $dateTime->format( time() , I18N_DATETIME_DEFAULT ) );
|
|
|
82 |
myPrint( $dateTime->format( time() , I18N_DATETIME_LONG ) );
|
|
|
83 |
myPrint( $dateTime->format( time() , I18N_DATETIME_FULL ) );
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
////////////////////////////////////////////
|
|
|
89 |
//
|
|
|
90 |
// DATE only
|
|
|
91 |
//
|
|
|
92 |
//
|
|
|
93 |
|
|
|
94 |
myPrint('<h1>DATE only</h1>');
|
|
|
95 |
|
|
|
96 |
//
|
|
|
97 |
// get the time now in format DEFAULT
|
|
|
98 |
//
|
|
|
99 |
myPrint( $dateTime->formatDate() );
|
|
|
100 |
|
|
|
101 |
//
|
|
|
102 |
// get the time now in format FULL
|
|
|
103 |
//
|
|
|
104 |
myPrint( $dateTime->formatDate( time() , I18N_DATETIME_FULL ) );
|
|
|
105 |
// or like this
|
|
|
106 |
$dateTime->setFormat( I18N_DATETIME_FULL );
|
|
|
107 |
myPrint( $dateTime->formatDate() );
|
|
|
108 |
|
|
|
109 |
// all possible formats
|
|
|
110 |
myPrint( $dateTime->formatDate( time() , I18N_DATETIME_SHORT ) );
|
|
|
111 |
myPrint( $dateTime->formatDate( time() , I18N_DATETIME_MEDIUM ) );
|
|
|
112 |
myPrint( $dateTime->formatDate( time() , I18N_DATETIME_DEFAULT ) );
|
|
|
113 |
myPrint( $dateTime->formatDate( time() , I18N_DATETIME_LONG ) );
|
|
|
114 |
myPrint( $dateTime->formatDate( time() , I18N_DATETIME_FULL ) );
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
////////////////////////////////////////////
|
|
|
119 |
//
|
|
|
120 |
// TIME only
|
|
|
121 |
//
|
|
|
122 |
//
|
|
|
123 |
|
|
|
124 |
myPrint('<h1>TIME only</h1>');
|
|
|
125 |
|
|
|
126 |
//
|
|
|
127 |
// get the time now in format DEFAULT
|
|
|
128 |
//
|
|
|
129 |
myPrint( $dateTime->formatTime() );
|
|
|
130 |
|
|
|
131 |
//
|
|
|
132 |
// get the time now in format FULL
|
|
|
133 |
//
|
|
|
134 |
myPrint( $dateTime->formatTime( time() , I18N_DATETIME_FULL ) );
|
|
|
135 |
// or like this
|
|
|
136 |
$dateTime->setFormat( I18N_DATETIME_FULL );
|
|
|
137 |
myPrint( $dateTime->formatTime() );
|
|
|
138 |
|
|
|
139 |
// all possible formats
|
|
|
140 |
myPrint( $dateTime->formatTime( time() , I18N_DATETIME_SHORT ) );
|
|
|
141 |
myPrint( $dateTime->formatTime( time() , I18N_DATETIME_MEDIUM ) );
|
|
|
142 |
myPrint( $dateTime->formatTime( time() , I18N_DATETIME_DEFAULT ) );
|
|
|
143 |
myPrint( $dateTime->formatTime( time() , I18N_DATETIME_LONG ) );
|
|
|
144 |
myPrint( $dateTime->formatTime( time() , I18N_DATETIME_FULL ) );
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
/*****************************
|
|
|
149 |
*
|
|
|
150 |
* CUSTOM formats
|
|
|
151 |
*
|
|
|
152 |
*/
|
|
|
153 |
|
|
|
154 |
myPrint('<h1>CUSTOM format</h1>');
|
|
|
155 |
|
|
|
156 |
//
|
|
|
157 |
// get the time now in a custom format
|
|
|
158 |
//
|
|
|
159 |
$myFormat = $dateTime->setFormat('l, d.m.Y - H:i:s \y\e\a\h');
|
|
|
160 |
myPrint( $dateTime->format() );
|
|
|
161 |
|
|
|
162 |
// switch back to default format
|
|
|
163 |
$dateTime->setFormat();
|
|
|
164 |
myPrint( $dateTime->format() );
|
|
|
165 |
|
|
|
166 |
// switch back to myFormat
|
|
|
167 |
$dateTime->setFormat( $myFormat );
|
|
|
168 |
myPrint( $dateTime->formatDate() );
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
myPrint('<h1>CUSTOM time-format</h1>');
|
|
|
173 |
//
|
|
|
174 |
// set custom time format only
|
|
|
175 |
//
|
|
|
176 |
$myTimeFormat = $dateTime->setTimeFormat('H \U\h\r i \M\i\n\u\t\e\n \u\n\d s \S\e\k\u\n\d\e\n');
|
|
|
177 |
myPrint( $dateTime->formatTime() );
|
|
|
178 |
|
|
|
179 |
// switch back to default format
|
|
|
180 |
$dateTime->setFormat();
|
|
|
181 |
myPrint( $dateTime->format() );
|
|
|
182 |
|
|
|
183 |
// switch back to myFormat
|
|
|
184 |
$dateTime->setFormat( $myTimeFormat );
|
|
|
185 |
myPrint( $dateTime->formatTime() );
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
function myPrint( $string )
|
|
|
192 |
{
|
|
|
193 |
print "$string<br><br>";
|
|
|
194 |
}
|
|
|
195 |
?>
|