skip to Main Content

I am coding a simple wordpress plugin and uses the time() function but I notice that it returns the server unix timestamp, not in the timezone that I set inside wordpress.

How can I retrieve the unix timestamp based on the wordpress timezone setting?

2

Answers


  1. Almost all of the main time functions accept parameters. I think it would be smart to change that.

    wp_date( string $format, int $timestamp = null, DateTimeZone $timezone
    = null ) Retrieves the date, in localized format.
    
    Parameters #Parameters $format (string) (Required) PHP date format.
    
    $timestamp (int) (Optional) Unix timestamp. Defaults to current time.
    
    Default value: null
    
    $timezone (DateTimeZone) (Optional) Timezone to output result in. Defaults to timezone from site settings.
    
    Default value: null
    
    Login or Signup to reply.
  2. Use current_time.

    <?php
        echo "Your local site time: " . date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) );
    ?>
    

    USEFUL LINKS

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search