Joy
(@joyously)
Did this just start happening? Did it coincide with anything you changed?
When the post shows tomorrow’s date, is the time correct?
Which editor are you using? Which WP version?
Some background: I’m in the process of learning WordPress, refreshing my knowledge of PHP and CSS, and experimenting with modifying page templates. My site is live, but in a subdomain that I’ve not told anyone about. I’m currently using a child theme of Zita. I’m using the WP 4.9 editor for most of the site work, and using MacOS TextWrangler with an FTP client to develop and upload my PHP files.
I do most of my work in the daytime, before 5:00 pm. So the wrong dates on posts were not evident. An attempt to put the current date in my site header, using an addition to my index.php template, was giving the wrong date, and that was the first indicator of the problem. Several different PHP functions were tried, all without success. (But an inline javascript worked correctly: <script> document.write(new Date().toLocaleDateString()); </script>.)
A post today at 4:58 pm local time had the correct date; another post at 5:02 pm had the incorrect date (meaning tomorrow). That seemed to be evidence that my installation was using UTC.
I also noted that some of the PHP date-related functions produced a date in the future, while another produced a date in the past. Additional experiments the next day caused one of the PHP functions to produce a date two days in the past. That date (by coincidence?) was also the date of my last published post.
Some Google searches found suggestions that using the newer OOP PHP functions might give better results, but I’ve not gotten very far yet with experiments with that.
All of the above happened last week. During that week, I also upgraded my site to WordPress 5.0.1. I cannot say whether that upgrade instigated the erroneous dates on my posts—I just wasn’t paying attention before a few days ago.
Additional experiments seem to indicate that anywhere I call a PHP date/time function, I need to precede it with:
<?php date_default_timezone_set(“America/Denver”); ?>
I assume that the WordPress editor does whatever is necessary whenever a post is published or updated, so the correct timestamp is saved in the post database. That may include checking the timezone in Settings/General. Does the editor also need to reset the PHP default timezone before every date/time action?
Also, what purpose does setting the default timezone in php.ini serve, if not to set the site-wide default?