wordpress get post time

Use the following code to get the post time in WordPress:

$post_date = get_the_time('Y-m-d H:i:s');
  1. Retrieve the time of the current post using the get_the_time function.
  2. Format the time according to the 'Y-m-d H:i:s' format, which represents year-month-day hour:minute:second.
  3. Store the formatted time in the variable $post_date.