The Date Helper file contains functions that assist in working with dates.
Many functions previously found in the CodeIgniter 3
date_helper have been moved to the Time class in CodeIgniter 4.
This helper is loaded using the following code:
The following functions are available:
- now([$timezone = null])
string) – Timezone
- Return type
It is recommended to use the Time class instead. Use
Time::now()->getTimestamp()to get the current UNIX timestamp.
If a timezone is not provided, it will return the current UNIX timestamp by
<?php echo now();
If any PHP supported timezone is provided, it will return a timestamp that is offset by the time difference. It is not the same as the current UNIX timestamp.
If you do not intend to set your master time reference to any other PHP supported timezone (which you’ll typically do if you run a site that lets each user set their own timezone settings) there is no benefit to using this function over PHP’s
- timezone_select([$class = '', $default = '', $what = \DateTimeZone::ALL, $country = null])
Preformatted HTML select field
- Return type
Generates a select form field of available timezones (optionally filtered by
$country). You can supply an option class to apply to the field to make formatting easier, as well as a default selected value.
<?php echo timezone_select('custom-select', 'America/New_York');