'Wordpress theme, get_lastpostmodified daylight savings
Have a problem with wordpress theme showing correct, last overall modified date of either posts or pages.
When i update or post a new page or post, on home page it shows the last date and time of when the information was update on the website.
Currently using this to achieve that:
Last updated on: <?php
$tmp = substr(get_lastpostmodified('gmt'),0,-3);
$tmp .= "-2";
echo date('Y-m-d H:i', strtotime($tmp)); ?>
The output of that on the page is:
Last updated on: 2022-03-28 05:30
This does all that i need however... it has problems with daylight savings. What would be the correct way of doing this ? Now with daylight savings it should be showing: Last updated on: 2022-03-28 06:30
In wordpress general settings i can see that wordpress knows and accounts for daylight savings, but how do i get that time and date ?
Thanks
Update:
Found the solution myself. Dont know if its the right way to do it but if someones interested.
Last updated on: <?php
date_default_timezone_set('Europe/Paris');
$tmp = get_lastpostmodified('gmt');
$tmp .= "+0";
echo date('Y-m-d H:i', strtotime($tmp)); ?>
Got timezone from: https://www.php.net/manual/en/timezones.php
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|