Skip Navigation

[Resolved] Function not showing correct time via custom code snippets after start of DST

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user had some custom code below.

add_shortcode('time-date', 'timedate');
function timedate() {
date_default_timezone_set( get_post_meta(get_the_ID(), 'wpcf-timezone-select-test'));
return date( 'H:i', current_time( 'timestamp' ));
}

This takes a location based on the PHP timezone location list below.
https://www.php.net/manual/en/timezones.php

It should render the time at the location that is specified, however the user notices that there is Daylight saving time activated even in countries that don't observe this.

Solution:

The user had set a specific timezone in their wordpress settings to a location that observes Daylight Saving Time. This had the effect that it will offset all the clock location by the DST rules.

To workaround this I would recommend setting your wordpress settings timezone to UTC or GMT with no offsets.

This support ticket is created 5 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 17 replies, has 2 voices.

Last updated by Ben 5 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1225686

Ben

Ah right Shane, I think I understand.

So to use this code to display times in different time zones I must have WordPress' default time zone set to GMT (which will cause all posting times to be GMT).

If I want to use a time zone offset for WordPress time then whatever this offset is, will affect the time zone code by the same amount.

Am I correct in thinking this?

#1225974

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ben,

Yes that is correct. So I would recommend keeping the timezone offset in it's neutral position of just GMT

Thanks,
Shane

#1226056

Ben

Thank you for all your help in solving this Shane, I really appreciate it!