Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

swedish boy on "date_i18n and timestamps"

$
0
0

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 all articles
Browse latest Browse all 8245

Trending Articles