My system timezone is UTC+1, MySQL is using this timezone and it's ok. Now I want to get the same timestamps in WordPress. As you know, WordPress modifies the current timezone so time() returns UTC-related time. There is a possibility to use current_time('timestamp') to get either UTC timestamp or Wordpress-timezone timestamp. But my WordPress timezone is different from the system one.
So the question is: how can I get SYSTEM timestamp inside the WordPress environment? I guess they should leave a core function for that since I can not use time() anymore.
Of course, there is a stupid solution like (time() + 3600), but I don't like it.
My system timezone is UTC+1, MySQL is using this timezone and it's ok. Now I want to get the same timestamps in WordPress. As you know, WordPress modifies the current timezone so time() returns UTC-related time. There is a possibility to use current_time('timestamp') to get either UTC timestamp or Wordpress-timezone timestamp. But my WordPress timezone is different from the system one.
So the question is: how can I get SYSTEM timestamp inside the WordPress environment? I guess they should leave a core function for that since I can not use time() anymore.
Of course, there is a stupid solution like (time() + 3600), but I don't like it.
Share Improve this question asked Feb 19, 2019 at 17:49 EpsiloncoolEpsiloncool 1473 silver badges14 bronze badges 9 | Show 4 more comments1 Answer
Reset to default -1You can use PHP's date()
function here, but usually first you'll need to run date_default_timezone_set
. UTC+1 looks like Central Europe time from what I can tell, so here's what I'd run:
<?php
date_default_timezone_set('Europe/Berlin');
echo date( 'D, d M Y H:i:s', now() );
?>
That will print out the current time from your server.
If you're looking to print out a timestamp from a post, you can use get_post_time and print replace the now()
function. Looks like this:
<?php
date_default_timezone_set('Europe/Berlin');
echo date( 'D, d M Y H:i:s', get_post_time('U', true) );
?>
date()
would display the time in that timezone. So I'm not sure what you're trying to do exactly. – Jacob Peattie Commented Feb 20, 2019 at 10:58time()
. What do you intend to do with this timestamp? – Jacob Peattie Commented Feb 20, 2019 at 11:26