Thanks for reaching out. To rule out the issue being with your theme or third party plugins please follow the steps below:
- Install and activate the Health Check & Troubleshooting plugin.
- Navigate to “Plugins > Health Check & Troubleshooting > Troubleshoot”.
- Vist the front end of your site and check the date (a default WordPress theme will be active)
- Exit troubleshooting mode and check your site once more
Do the dates match when in troubleshooting mode (independent of your AMP URLs)?
Hm, yes, the dates are correct… But my problem is a four-hour time difference, which wouldn’t show up in a default theme, because it only shows the date, not the time.
Did that answer your question?
Yes, I was able to verify, the time stamp is correct in troubleshooting mode.
Thanks for the update. Is the timestamp at present correct in your AMP URLs or your non AMP URLs?
Yes, I was able to verify, the time stamp is correct in troubleshooting mode.
You can use the same troubleshooting plugin to eliminate the issue being plugin or theme related if you enable one by one using troubleshooting mode.
The AMP plugin also uses the below in it’s reader mode templates:
human_time_diff( $this->get( 'post_publish_timestamp' ), time() )
You’ll also find the reader mode time template here. You can overwrite that file by creating your own amp folder within your activate themes root directory and placing that modified file in there.
Let me know which timestamp is correct on your site at present.
No offense, but you sorta restated my original post. I know where the code is located…
I don’t understand why the timestamp is off only on AMP. Is the solution really just “subtract four hours on AMP”? It seems like there should be some explanation for the discrepancy.
Apologies, I did indeed. If you’d like to share your Site Health information privately using this form we’d be happy to see if there’s anything we notice.
Please also share whether the same issue occurs with a core theme temporarily activated.
I think I can see the issue. I’m able to reproduce it as well.
I’ve sent my timezone to Pacific/Los_Angeles, and when I set a published post 2-hours in the past, the result I get is my post saying “9 hours ago”.
Note that Pacific/Los_Angeles is GMT-7, and 2+7 is… 9. So the issue is that the local timestamp is being used for the human_time_diff() comparison, when it should be the GMT one.
@rexsorgatz Please try adding this code to your custom theme’s function.php or a custom plugin:
add_filter(
'amp_post_template_data',
function ( $data, WP_Post $post ) {
$data['post_publish_timestamp'] = get_post_time( 'U', true, $post );
return $data;
},
10,
2
);
That should fix the issue for you. We’ll fix the issue in the next release of the AMP plugin.
Pull request opened to fix the issue in v2.0.2: https://github.com/ampproject/amp-wp/pull/5335