Whats the way to format a date after using get_posts()
echo date(‘Y-m-d h:i:s’, strtotime($cp->post_date)); … or better use the wordpress functionado echo mysql2date(‘Y-m-d h:i:s’, $cp->post_date);
echo date(‘Y-m-d h:i:s’, strtotime($cp->post_date)); … or better use the wordpress functionado echo mysql2date(‘Y-m-d h:i:s’, $cp->post_date);
Not sure what is the question, but the use of time() is wrong as it will give you at best the local time of the server and not the local time of the site which takes into consideration the time zone configuration of WordPress. The function that you should use is current_time.
I’m not sure why EliasNS’ answer is marked correct, as far as I’m aware (and from the documentation), the second parameter of DateTime::__construct(), if provided, should be a DateTimeZone instance. The problem then becomes, how we do we create a DateTimeZone instance. This is easy if the user has selected a city as their timezone, … Read more
Somehow I missed the current_time function, which gives a good description of the situation and how to properly deal with the need to get the current blog-local time. http://codex.wordpress.org/Function_Reference/current_time Though the purist in me still hates how WP makes the time zone setting in php.ini obsolete without giving you a choice. *grumble grumble*
They are, very similar but with some nuances: function get_the_date( $d = ” ) { global $post; $the_date=””; if ( ” == $d ) $the_date .= mysql2date(get_option(‘date_format’), $post->post_date); else $the_date .= mysql2date($d, $post->post_date); return apply_filters(‘get_the_date’, $the_date, $d); } function get_the_time( $d = ”, $post = null ) { $post = get_post($post); if ( ” == … Read more
If you don’t add a post_date then WordPress fills it automatically with the current date and time. To set another date and time [ Y-m-d H:i:s ] is the right structure. An example below with your code. $postdate=”2010-02-23 18:57:33″; $new_post = array( ‘post_title’ => $title, ‘post_content’ => $description, ‘post_date’ => $postdate, ‘post_status’ => ‘publish’, ‘post_parent’ … Read more