Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1038866

    Hi, I’m using blog template of Enfold, currently the template only displays date of my posts, but I need to display the hour, minute and second of posting, how to make that?

    #1039144

    Hey sunwuye,

    DO you mean on the single post?

    Could you please give us a link to your website, we need more context to be able to help you.

    Best regards,
    Victoria

    #1039194

    Yes, please check my link below.

    #1039231

    Hi,
    I found a code example to base this function on at this GitHub The example turned the date into a time and then calculated how long “ago” the post was posted, I removed the final calculation and was left with the date and exact time of the post. The date & time can be adjusted using the standard WordPress date & time format.
    Try adding this code to the end of your functions.php file in Appearance > Editor:

    
    function mm_post_date_time( $formatted, $format, $the_post = false ) {
    
    	if ( ! $the_post ) {
    		global $post;
    		$the_post = $post;
    	}
    
    	$post_date = get_post_time( 'M d Y g:i:s a', true, $the_post );
    
    	$output = $post_date;
    
    	return $output;
    }
    add_filter( 'the_time', 'mm_post_date_time', 10, 2 );
    add_filter( 'get_the_time', 'mm_post_date_time', 10, 3 );
    add_filter( 'the_date', 'mm_post_date_time', 10, 2 );
    add_filter( 'get_the_date', 'mm_post_date_time', 10, 3 );

    Best regards,
    Mike

    #1039245

    Thanks Mike, could you tell me where to edit the time format? I tried to replace ‘M d Y g:i:s a’ part, but no change happened.

    And how to display my local time, which is UTC+8?

    • This reply was modified 6 years, 7 months ago by sunwuye.
    #1039329

    Hi,
    To change the format edit the ‘M d Y g:i:s a’ part, following the link above. This works on my localhost, so it should work for you too. Or see if changing the format at WordPress > Settings > General > Date Format makes a difference, it does not for me.
    What format are you trying for?
    As for local time vs server time, I will have to research this more.

    Best regards,
    Mike

    #1039478

    Hi Mike, the format has changed now, thanks! And I edited functions-enfold.php instead of functions.php, and it works as well, hope there would be no other error.

    I have to display the local time because this is required by Baidu in China now, so that it could better identify original content.

    It seems that the “current_time” code needs to be edited (<?php $time = current_time( $type, $gmt = 0 ); ?>
    ) according to this page: https://codex.wordpress.org/Function_Reference/current_time, but I cannot find such code anywhere,

    • This reply was modified 6 years, 7 months ago by sunwuye.
    #1039531

    Hi,
    Thanks for the link it did help lead me to the correct function, so what you will need to do is ensure that WordPress > Settings > General > Timezone is set correctly, there is a info box that tells you what WordPress thinks is the local time which updates when you save the settings:
    2018-12-01-005012
    Then change the function to this one:

    function mm_post_date_time( $formatted, $format, $the_post = false ) {
    
    	if ( ! $the_post ) {
    		global $post;
    		$the_post = $post;
    	}
    
    	$post_date = get_post_time( 'M d Y g:i:s a', $gmt = 0, $the_post);
    
    	$output = $post_date;
    
    	return $output;
    }
    add_filter( 'the_time', 'mm_post_date_time', 10, 2 );
    add_filter( 'get_the_time', 'mm_post_date_time', 10, 3 );
    add_filter( 'the_date', 'mm_post_date_time', 10, 2 );
    add_filter( 'get_the_date', 'mm_post_date_time', 10, 3 );
    

    Best regards,
    Mike

    #1040081

    Great, it works now, thanks Mike!

    #1040184

    Hi sunwuye,

    Glad that we could help. :)
    Let us know if you need further assistance or if we can close this thread.

    Best regards,
    Nikko

    #1040715

    So is it OK to just put the codes in the end of the functions-enfold.php or functions.php file?

    #1040736

    Hi,
    I recommend placing the code at the end of your functions.php, while it will work in functions-enfold.php it’s not proper.
    Unless there is anything else we can assist with on this issue, shall we close this then?

    Best regards,
    Mike

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘How to display exact posting time?’ is closed to new replies.