date_i18n and timestamps
-
This was a bit puzzling to me, but
date_i18n
doesn’t adjust to local timezone as one would think. If you set your timezone in wp-admin to GMT+1 this is what happens in the following 2 examples.Let’s say GMT time is 17:05.
echo date_i18n('H:i'); // Will output current hours and minutes of local timezone //Result: 18:05
However if you give this function a custom timestamp or time():
echo date_i18n('H:i', time()); // Output: 17:05 // $some_timestamp is set to time()-3600; echo date_i18n('H:i', $some_timestamp); // Output: 16:05
In both last examples date_i18n outputs GMT time.
The fix is to do add the following to your timestamp:
$timestamp += get_option( 'gmt_offset' ) * 3600; echo date_i18n('H:i', $timestamp );
Almost a bug if you ask me.
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘date_i18n and timestamps’ is closed to new replies.