0

In my plugin, I am trying to get the current date/time of the blog into the code but it seems to be returning a odd date/time. If i put a new post on the blog it does show the correct date/time so I am not sure what the issue is. Am I handling the code incorrectly? (Post Time: Published on: Feb 13, 2012 @ 22:45)

PHP Code

<?
$t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
echo "<h1>BLOG TIME</h1>";
echo $t_time . "<br>";
echo "<br>";
echo "<h1>SERVER TIME</h1>";
echo date("Y/m/d g:i:s A");
?>

OUTPUT BLOG TIME 2011/05/20 10:28:16 PM

SERVER TIME 2012/02/14 5:41:35 AM

9

There is a function in WordPress called current_time(); which you pass either 'timestamp' or 'mysql' to and it returns a time.

For more information: http://codex.wordpress.org/Function_Reference/current_time

  • +1. I would add that WordPress forces the server timezone to be UTC, which is why you should use WordPress' functions (as they take this into account) rather than native PHP ones. – Stephen Harris Feb 14 '12 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.