admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 2 | <html>
|
| 3 | <head>
|
| 4 |
|
| 5 | <title>Code Igniter User Guide</title>
|
| 6 |
|
| 7 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 8 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 9 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 13 | <script type="text/javascript">
|
| 14 | window.onload = function() {
|
| 15 | myHeight = new fx.Height('nav', {duration: 400});
|
| 16 | myHeight.hide();
|
| 17 | }
|
| 18 | </script>
|
| 19 |
|
| 20 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 21 | <meta http-equiv='expires' content='-1' />
|
| 22 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 23 | <meta name='robots' content='all' />
|
| 24 | <meta name='author' content='Rick Ellis' />
|
| 25 | <meta name='description' content='Code Igniter User Guide' />
|
| 26 |
|
| 27 | </head>
|
| 28 | <body>
|
| 29 |
|
| 30 | <!-- START NAVIGATION -->
|
| 31 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 32 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
|
| 33 | <div id="masthead">
|
| 34 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 35 | <tr>
|
admin | 41a1685 | 2006-09-26 18:17:19 +0000 | [diff] [blame] | 36 | <td><h1>Code Igniter User Guide Version 1.5.0</h1></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 37 | <td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
|
| 38 | </tr>
|
| 39 | </table>
|
| 40 | </div>
|
| 41 | <!-- END NAVIGATION -->
|
| 42 |
|
| 43 |
|
| 44 | <!-- START BREADCRUMB -->
|
| 45 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 46 | <tr>
|
| 47 | <td id="breadcrumb">
|
| 48 | <a href="http://www.codeigniter.com/">Code Igniter Home</a> ›
|
| 49 | <a href="../index.html">User Guide Home</a> ›
|
| 50 | Directory Helper
|
| 51 | </td>
|
| 52 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
|
| 53 | </tr>
|
| 54 | </table>
|
| 55 | <!-- END BREADCRUMB -->
|
| 56 |
|
| 57 | <br clear="all" />
|
| 58 |
|
| 59 |
|
| 60 | <!-- START CONTENT -->
|
| 61 | <div id="content">
|
| 62 |
|
| 63 |
|
| 64 | <h1>Date Helper</h1>
|
| 65 |
|
| 66 | <p>The Date Helper file contains functions that help you work with dates.</p>
|
| 67 |
|
| 68 |
|
| 69 | <h2>Loading this Helper</h2>
|
| 70 |
|
| 71 | <p>This helper is loaded using the following code:</p>
|
| 72 | <code>$this->load->helper('date');</code>
|
| 73 |
|
| 74 |
|
| 75 | <p>The following functions are available:</p>
|
| 76 |
|
| 77 | <h2>now()</h2>
|
| 78 |
|
| 79 | <p>Returns the current time as a Unix timestamp, referenced either to your server's local time or GMT, based on the "time reference"
|
| 80 | setting in your config file. If you do not intend to set your master time reference to GMT (which you'll typically do if you
|
| 81 | run a site that lets each user set their own timezone settings) there is no benefit to using this function over PHP's time() function.
|
| 82 | </p>
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 | <h2>mdate()</h2>
|
| 88 |
|
| 89 | <p>This function is identical to PHPs <a href="http://www.php.net/date">date()</a> function, except that it lets you
|
| 90 | use MySQL style date codes, where each code letter is preceded with a percent sign: %Y %m %d etc.</p>
|
| 91 |
|
| 92 | <p>The benefit of doing dates this way is that you don't have to worry about escaping any characters that
|
| 93 | are not date codes, as you would normally have to do with the date() function. Example:</p>
|
| 94 |
|
| 95 | <code>$datestring = "Year: %Y Month: %m Day: %d - %h:%i %a";<br />
|
| 96 | $time = time();<br />
|
| 97 | <br />
|
| 98 | echo mdate($datestring, $time);</code>
|
| 99 |
|
| 100 | <p>If a timestamp is not included in the second parameter the current time will be used.</p>
|
| 101 |
|
| 102 |
|
admin | e8f6eb6 | 2006-10-02 06:46:16 +0000 | [diff] [blame] | 103 | <h2>standard_date()</h2>
|
| 104 |
|
| 105 | <p>Lets you generate a date string in one of several standardized formats. Example:</p>
|
| 106 |
|
| 107 | <code>
|
| 108 | $format = 'DATE_RFC822';<br />
|
| 109 | $time = time();<br />
|
| 110 | <br />
|
| 111 | echo standard_date($format, $time);
|
| 112 | </code>
|
| 113 |
|
| 114 | <p>The first parameter must contain the format, the second parameter must contain the date as a Unix timestamp.</p>
|
| 115 |
|
| 116 | <p>Supported formats:</p>
|
| 117 |
|
| 118 | <ul>
|
| 119 | <li>DATE_ATOM</li>
|
| 120 | <li>DATE_COOKIE</li>
|
| 121 | <li>DATE_ISO8601</li>
|
| 122 | <li>DATE_RFC822</li>
|
| 123 | <li>DATE_RFC850</li>
|
| 124 | <li>DATE_RFC1036</li>
|
| 125 | <li>DATE_RFC1123</li>
|
| 126 | <li>DATE_RFC2822</li>
|
| 127 | <li>DATE_RSS</li>
|
| 128 | <li>DATE_W3C</li>
|
| 129 | </ul>
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 134 | <h2>local_to_gmt()</h2>
|
| 135 |
|
| 136 | <p>Takes a Unix timestamp as input and returns it as GMT. Example:</p>
|
| 137 |
|
| 138 | <code>$now = time();<br />
|
| 139 | <br />
|
| 140 | $gmt = local_to_gmt($now);</code>
|
| 141 |
|
| 142 |
|
| 143 | <h2>gmt_to_local()</h2>
|
| 144 |
|
| 145 | <p>Takes a Unix timestamp (referenced to GMT) as input, and converts it to a localized timestamp based on the
|
| 146 | timezone and Daylight Saving time submitted. Example:</p>
|
| 147 |
|
| 148 | <code>
|
| 149 | $timestamp = '1140153693';<br />
|
| 150 | $timezone = 'UM8';<br />
|
| 151 | $daylight_saving = TRUE;<br />
|
| 152 | <br />
|
| 153 | echo gmt_to_local($timestamp, $timezone, daylight_saving);</code>
|
| 154 |
|
| 155 | <p><strong>Note:</strong> For a list of timezones see the reference at the bottom of this page.</p>
|
| 156 |
|
| 157 | <h2>mysql_to_unix()</h2>
|
| 158 |
|
| 159 | <p>Takes a MySQL Timestamp as input and returns it as Unix. Example:</p>
|
| 160 |
|
| 161 | <code>$mysql = '20061124092345';<br />
|
| 162 | <br />
|
| 163 | $unix = mysql_to_unix($mysql);</code>
|
| 164 |
|
| 165 |
|
| 166 | <h2>unix_to_human()</h2>
|
| 167 |
|
| 168 | <p>Takes a Unix timestamp as input and returns it in a human readable format with this prototype:</p>
|
| 169 |
|
| 170 | <code>YYYY-MM-DD HH:MM:SS AM/PM</code>
|
| 171 |
|
| 172 | <p>This can be useful if you need to display a date in a form field for submission.</p>
|
| 173 |
|
| 174 | <p>The time can be formatted with or without seconds, and it can be set to European or US format. If only
|
| 175 | the timestamp is submitted it will return the time without seconds formatted for the U.S. Examples:
|
| 176 |
|
| 177 | <code>$now = time();<br />
|
| 178 | <br />
|
| 179 | echo unix_to_human($now); // U.S. time, no seconds<br />
|
| 180 | <br />
|
| 181 | echo unix_to_human($now, TRUE, 'us'); // U.S. time with seconds<br />
|
| 182 | <br />
|
| 183 | echo unix_to_human($now, TRUE, 'eu'); // Euro time with seconds</code>
|
| 184 |
|
| 185 |
|
| 186 | <h2>human_to_unix()</h2>
|
| 187 |
|
| 188 | <p>The opposite of the above function. Takes a "human" time as input and returns it as Unix. This function is
|
| 189 | useful if you accept "human" formatted dates submitted via a form. Returns FALSE (boolean) if
|
| 190 | the date string passed to it is not formatted as indicated above. Example:</p>
|
| 191 |
|
| 192 | <code>$now = time();<br />
|
| 193 | <br />
|
| 194 | $human = unix_to_human($now);<br />
|
| 195 | <br />
|
| 196 | $unix = human_to_unix($human);</code>
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 | <h2>timespan()</h2>
|
| 203 |
|
| 204 | <p>Formats a unix timestamp so that is appears similar to this:</p>
|
| 205 |
|
| 206 | <code>1 Year, 10 Months, 2 Weeks, 5 Days, 10 Hours, 16 Minutes</code>
|
| 207 |
|
| 208 | <p>The first parameter must contain a Unix timestamp. The second parameter must contain a
|
| 209 | timestamp that is greater that the first timesamp. If the second parameter empty, the current time will be used. The most common purpose
|
| 210 | for this function is to show how much time has elapsed from some point in time in the past to now. Example:</p>
|
| 211 |
|
| 212 | <code>$post_date = '1079621429';<br />
|
| 213 | $now = time();<br />
|
| 214 | <br />
|
| 215 | echo timespan($post_date, $now);</code>
|
| 216 |
|
| 217 | <p class="important"><strong>Note:</strong> The text generated by this function is found in the following language file: language/<your_lang>/date_lang.php</p>
|
| 218 |
|
| 219 |
|
| 220 | <h2>days_in_month()</h2>
|
| 221 |
|
| 222 | <p>Returns the number of days in a given month/year. Takes leap years into account. Example:</p>
|
| 223 | <code>echo days_in_month(06, 2005);</code>
|
| 224 |
|
| 225 | <p>If the second parameter is empty, the current year will be used.</p>
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 | <h2>timezone_menu()</h2>
|
| 230 |
|
| 231 | <p>Generates a pull-down menu of timezones, like this one:</p>
|
| 232 |
|
| 233 | <form>
|
| 234 | <select name="timezones">
|
| 235 | <option value='UM12'>(UTC - 12:00) Enitwetok, Kwajalien</option>
|
| 236 | <option value='UM11'>(UTC - 11:00) Nome, Midway Island, Samoa</option>
|
| 237 | <option value='UM10'>(UTC - 10:00) Hawaii</option>
|
| 238 | <option value='UM9'>(UTC - 9:00) Alaska</option>
|
| 239 | <option value='UM8'>(UTC - 8:00) Pacific Time</option>
|
| 240 | <option value='UM7'>(UTC - 7:00) Mountain Time</option>
|
| 241 | <option value='UM6'>(UTC - 6:00) Central Time, Mexico City</option>
|
| 242 | <option value='UM5'>(UTC - 5:00) Eastern Time, Bogota, Lima, Quito</option>
|
| 243 | <option value='UM4'>(UTC - 4:00) Atlantic Time, Caracas, La Paz</option>
|
| 244 | <option value='UM25'>(UTC - 3:30) Newfoundland</option>
|
| 245 | <option value='UM3'>(UTC - 3:00) Brazil, Buenos Aires, Georgetown, Falkland Is.</option>
|
| 246 | <option value='UM2'>(UTC - 2:00) Mid-Atlantic, Ascention Is., St Helena</option>
|
| 247 | <option value='UM1'>(UTC - 1:00) Azores, Cape Verde Islands</option>
|
| 248 | <option value='UTC' selected='selected'>(UTC) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia</option>
|
| 249 | <option value='UP1'>(UTC + 1:00) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome</option>
|
| 250 | <option value='UP2'>(UTC + 2:00) Kaliningrad, South Africa, Warsaw</option>
|
| 251 | <option value='UP3'>(UTC + 3:00) Baghdad, Riyadh, Moscow, Nairobi</option>
|
| 252 | <option value='UP25'>(UTC + 3:30) Tehran</option>
|
| 253 | <option value='UP4'>(UTC + 4:00) Adu Dhabi, Baku, Muscat, Tbilisi</option>
|
| 254 | <option value='UP35'>(UTC + 4:30) Kabul</option>
|
| 255 | <option value='UP5'>(UTC + 5:00) Islamabad, Karachi, Tashkent</option>
|
| 256 | <option value='UP45'>(UTC + 5:30) Bombay, Calcutta, Madras, New Delhi</option>
|
| 257 | <option value='UP6'>(UTC + 6:00) Almaty, Colomba, Dhakra</option>
|
| 258 | <option value='UP7'>(UTC + 7:00) Bangkok, Hanoi, Jakarta</option>
|
| 259 | <option value='UP8'>(UTC + 8:00) Beijing, Hong Kong, Perth, Singapore, Taipei</option>
|
| 260 | <option value='UP9'>(UTC + 9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk</option>
|
| 261 | <option value='UP85'>(UTC + 9:30) Adelaide, Darwin</option>
|
| 262 | <option value='UP10'>(UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok</option>
|
| 263 | <option value='UP11'>(UTC + 11:00) Magadan, New Caledonia, Solomon Islands</option>
|
| 264 | <option value='UP12'>(UTC + 12:00) Auckland, Wellington, Fiji, Marshall Island</option>
|
| 265 | </select>
|
| 266 | </form>
|
| 267 |
|
| 268 | <p>This menu is useful if you run a membership site in which your users are allowed to set their local timezone value.</p>
|
| 269 |
|
| 270 | <p>The first paramater lets you set the "selected" state of the menu. For example, to set Pacific time as the default you will do this:</p>
|
| 271 |
|
| 272 | <code>echo timezone_menu('UM8');</code>
|
| 273 |
|
| 274 | <p>Please see the timezone reference below to see the values of this menu.</p>
|
| 275 |
|
| 276 | <p>The second parameter lets you set a CSS class name for the menu.</p>
|
| 277 |
|
| 278 | <p class="important"><strong>Note:</strong> The text contained in the menu is found in the following language file: language/<your_lang>/date_lang.php</p>
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 | <h2>Timezone Reference</h2>
|
| 283 |
|
| 284 | <p>The following table indicates each timezone and its location.</p>
|
| 285 |
|
| 286 | <table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
|
| 287 | <tr>
|
| 288 | <th>Time Zone</th>
|
| 289 | <th>Location</th>
|
| 290 | </tr><tr>
|
| 291 |
|
| 292 | <td class="td">UM12</td><td class="td">(UTC - 12:00) Enitwetok, Kwajalien</td>
|
| 293 | </tr><tr>
|
| 294 | <td class="td">UM11</td><td class="td">(UTC - 11:00) Nome, Midway Island, Samoa</td>
|
| 295 | </tr><tr>
|
| 296 | <td class="td">UM10</td><td class="td">(UTC - 10:00) Hawaii</td>
|
| 297 | </tr><tr>
|
| 298 | <td class="td">UM9</td><td class="td">(UTC - 9:00) Alaska</td>
|
| 299 | </tr><tr>
|
| 300 | <td class="td">UM8</td><td class="td">(UTC - 8:00) Pacific Time</td>
|
| 301 | </tr><tr>
|
| 302 | <td class="td">UM7</td><td class="td">(UTC - 7:00) Mountain Time</td>
|
| 303 | </tr><tr>
|
| 304 | <td class="td">UM6</td><td class="td">(UTC - 6:00) Central Time, Mexico City</td>
|
| 305 | </tr><tr>
|
| 306 | <td class="td">UM5</td><td class="td">(UTC - 5:00) Eastern Time, Bogota, Lima, Quito</td>
|
| 307 | </tr><tr>
|
| 308 | <td class="td">UM4</td><td class="td">(UTC - 4:00) Atlantic Time, Caracas, La Paz</td>
|
| 309 | </tr><tr>
|
| 310 | <td class="td">UM25</td><td class="td">(UTC - 3:30) Newfoundland</td>
|
| 311 | </tr><tr>
|
| 312 | <td class="td">UM3</td><td class="td">(UTC - 3:00) Brazil, Buenos Aires, Georgetown, Falkland Is.</td>
|
| 313 | </tr><tr>
|
| 314 | <td class="td">UM2</td><td class="td">(UTC - 2:00) Mid-Atlantic, Ascention Is., St Helena</td>
|
| 315 | </tr><tr>
|
| 316 | <td class="td">UM1</td><td class="td">(UTC - 1:00) Azores, Cape Verde Islands</td>
|
| 317 | </tr><tr>
|
| 318 | <td class="td">(UTC</td><td class="td">(UTC) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia</td>
|
| 319 | </tr><tr>
|
| 320 | <td class="td">UP1</td><td class="td">(UTC + 1:00) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome</td>
|
| 321 | </tr><tr>
|
| 322 | <td class="td">UP2</td><td class="td">(UTC + 2:00) Kaliningrad, South Africa, Warsaw</td>
|
| 323 | </tr><tr>
|
| 324 | <td class="td">UP3</td><td class="td">(UTC + 3:00) Baghdad, Riyadh, Moscow, Nairobi</td>
|
| 325 | </tr><tr>
|
| 326 | <td class="td">UP25</td><td class="td">(UTC + 3:30) Tehran</td>
|
| 327 | </tr><tr>
|
| 328 | <td class="td">UP4</td><td class="td">(UTC + 4:00) Adu Dhabi, Baku, Muscat, Tbilisi</td>
|
| 329 | </tr><tr>
|
| 330 | <td class="td">UP35</td><td class="td">(UTC + 4:30) Kabul</td>
|
| 331 | </tr><tr>
|
| 332 | <td class="td">UP5</td><td class="td">(UTC + 5:00) Islamabad, Karachi, Tashkent</td>
|
| 333 | </tr><tr>
|
| 334 | <td class="td">UP45</td><td class="td">(UTC + 5:30) Bombay, Calcutta, Madras, New Delhi</td>
|
| 335 | </tr><tr>
|
| 336 | <td class="td">UP6</td><td class="td">(UTC + 6:00) Almaty, Colomba, Dhakra</td>
|
| 337 | </tr><tr>
|
| 338 | <td class="td">UP7</td><td class="td">(UTC + 7:00) Bangkok, Hanoi, Jakarta</td>
|
| 339 | </tr><tr>
|
| 340 | <td class="td">UP8</td><td class="td">(UTC + 8:00) Beijing, Hong Kong, Perth, Singapore, Taipei</td>
|
| 341 | </tr><tr>
|
| 342 | <td class="td">UP9</td><td class="td">(UTC + 9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk</td>
|
| 343 | </tr><tr>
|
| 344 | <td class="td">UP85</td><td class="td">(UTC + 9:30) Adelaide, Darwin</td>
|
| 345 | </tr><tr>
|
| 346 | <td class="td">UP10</td><td class="td">(UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok</td>
|
| 347 | </tr><tr>
|
| 348 | <td class="td">UP11</td><td class="td">(UTC + 11:00) Magadan, New Caledonia, Solomon Islands</td>
|
| 349 | </tr><tr>
|
| 350 | <td class="td">UP12</td><td class="td">(UTC + 12:00) Auckland, Wellington, Fiji, Marshall Island</td>
|
| 351 | </tr>
|
| 352 | </table>
|
| 353 |
|
| 354 |
|
| 355 | </div>
|
| 356 | <!-- END CONTENT -->
|
| 357 |
|
| 358 |
|
| 359 | <div id="footer">
|
| 360 | <p>
|
| 361 | Previous Topic: <a href="cookie_helper.html">Cookie Helper</a>
|
| 362 | ·
|
| 363 | <a href="#top">Top of Page</a> ·
|
| 364 | <a href="../index.html">User Guide Home</a> ·
|
| 365 | Next Topic: <a href="directory_helper.html">Directory Helper</a>
|
| 366 | <p>
|
| 367 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 368 | </div>
|
| 369 |
|
| 370 | </body>
|
| 371 | </html> |