Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 7 down vote accepted

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

share|improve this answer
    
+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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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