Force time zone in strtotime function
-
Hi,
I’m saving a date in my database with the
strtotime()function and am looking for an approved way to force the timezone to be UTC. Currently I do something like this:my_function() {
// get current timezone
$current_zone = date_default_timezone_get();
// set utc timezone for strtotime
date_default_timezone_set( 'UTC' );
// save my date
update_post_meta( $post_id, 'date', sanitize_text_field( strtotime( $my_date_value ) ) );
// set current timezone again
date_default_timezone_set( $current_zone );
}Works fine but not allowed according to the PCP:
Using date_default_timezone_set() and similar isn’t allowed, instead use WP internal timezone support.
Is there another way to do the same?(I did post about this before, but was not able to fix it. And it seems that PCP classified it as a warning at that time, but now it’s an error)
Guido
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
The topic ‘Force time zone in strtotime function’ is closed to new replies.