get_the_time

Retrieve the time at which the post was written.

Description

(string|int|false) get_the_time( (string) $d = '', (null) $post = null ); 

Returns (string|int|false)

Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure.

Parameters (2)

0. $d — Optional. (string) => ''
Format to use for retrieving the time the post was written. Either G,, U, or php date format defaults to the value specified in the time_format option. Default empty.
1. $post — Optional. (null) => null
WP_Post object or ID. Default is global $post object.

Usage

  1. if ( !function_exists( 'get_the_time' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3. $d = ''; 
  4.  
  5. // WP_Post object or ID. Default is global $post object. 
  6. $post = null; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = get_the_time($d, $post); 
  10.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function get_the_time( $d = '', $post = null ) { 
  2. $post = get_post($post); 
  3.  
  4. if ( ! $post ) { 
  5. return false; 
  6.  
  7. if ( '' == $d ) 
  8. $the_time = get_post_time(get_option('time_format'), false, $post, true); 
  9. else 
  10. $the_time = get_post_time($d, false, $post, true); 
  11.  
  12. /** 
  13. * Filters the time a post was written. 
  14. * @since 1.5.0 
  15. * @param string $the_time The formatted time. 
  16. * @param string $d Format to use for retrieving the time the post was written. 
  17. * Accepts 'G', 'U', or php date format value specified 
  18. * in 'time_format' option. Default empty. 
  19. * @param int|WP_Post $post WP_Post object or ID. 
  20. */ 
  21. return apply_filters( 'get_the_time', $the_time, $d, $post );