Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

hey guys, it's weird and I've never experienced that before. I've created a new blog and a custom theme. I'm using <?php echo date("H:i"); ?>in my theme.

The time that's put is 2h earlier. e.g. if it's actually 16:00 o'clock the date generated with date() is 14:00.

I don't know why that happens? I'm using the german wordpress version with the german language pack.

Also doesn't make a difference when putting

setlocale(LC_ALL, 'de_DE');
date_default_timezone_set('Europe/Berlin');

into wp-config.php.

any idea how I could solve that? the time set in my wordpress settings is UTC+2 which is the correct time.

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

This could probably make exquisite debugging session, but taking in account it's Friday evening - just use date_i18n() instead and let WordPress deal with a huge mess that time/date issues usually are.

share|improve this answer
add comment

Try

echo date('H:i', current_time('timestamp'));

and enjoy!

share|improve this answer
    
I'm not sure that date_i18n() will solve the offset issue. wp-settings.php sets date_default_timezone_set('UTC') and all subsequent calls to date() will be based on that offset unless you switch it. date_i18n() doesn't do anything about this, just looks at the locale for formatting information. The WordPress function current_time() on the other hand, will take the current time() and then adds the GMT offset as defined in your Settings > General pane, which gives you your effective local time, provided you've set it correctly in your Settings. +1 –  Tom Auger Oct 2 '12 at 21:32
add comment

Doesn't the PHP date() function merely return a value based on the server timestamp? So, what is the current time for your server, compared to your local time? Does that account for the two-hour difference?

share|improve this answer
    
Yes, but it's influenced by date_default_timezone_set() which is set to UTC in wp-settings.php, so you'll always get UTC timecode unless you add in the GMT offset. –  Tom Auger Oct 2 '12 at 21:33
add comment

I think that the problem is that the server date is different between your. Your server has a different date between your probably because it's placed in another state.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.