Php JSON日期未在站点上正确显示

Php JSON日期未在站点上正确显示,php,json,Php,Json,我有一本书。我喜欢它。我想抓取发布日期并将其发布到网站上。feed显示“latestPublishedAt”,值为1483582815852,转换为11月的日期,而profile显示的是1月5日的日期。为什么日期不同?请导游 <?php function file_get_contents_custom($url){ $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch,

我有一本书。我喜欢它。我想抓取发布日期并将其发布到网站上。feed显示“latestPublishedAt”,值为1483582815852,转换为11月的日期,而profile显示的是1月5日的日期。为什么日期不同?请导游

<?php

function file_get_contents_custom($url){
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    $contents = curl_exec($ch);
    if (curl_errno($ch)) {
        return curl_error($ch);
    } else {
        curl_close($ch);
    }
    if (!is_string($contents) || !strlen($contents)) {
        return false;
    } else {
        return $contents;
    }
}

/**

 * The plugin bootstrap file

 *

 * This file is read by WordPress to generate the plugin information in the plugin

 * admin area. This file also includes all of the dependencies used by the plugin,

 * registers the activation and deactivation functions, and defines a function

 * that starts the plugin.

 *

 * @link              http://www.acekyd.com

 * @since             1.0.0

 * @package           Display_Medium_Posts

 *

 * @wordpress-plugin

 * Plugin Name:       Display Medium Posts

 * Plugin URI:        https://github.com/acekyd/display-medium-posts

 * Description:       Display Medium Posts is a wordpress plugin that allows users display posts from medium.com on any part of their website.

 * Version:           2.0.0

 * Author:            AceKYD

 * Author URI:        http://www.acekyd.com

 * License:           GPL-2.0+

 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt

 * Text Domain:       display-medium-posts

 * Domain Path:       /languages

 */



// If this file is called directly, abort.

if ( ! defined( 'WPINC' ) ) {

    die;

}




/**

 * The code that runs during plugin activation.

 * This action is documented in includes/class-display-medium-posts-activator.php

 */

function activate_display_medium_posts() {

    require_once plugin_dir_path( __FILE__ ) . 'includes/class-display-medium-posts-activator.php';

    Display_Medium_Posts_Activator::activate();

}



/**

 * The code that runs during plugin deactivation.

 * This action is documented in includes/class-display-medium-posts-deactivator.php

 */

function deactivate_display_medium_posts() {

    require_once plugin_dir_path( __FILE__ ) . 'includes/class-display-medium-posts-deactivator.php';

    Display_Medium_Posts_Deactivator::deactivate();

}



register_activation_hook( __FILE__, 'activate_display_medium_posts' );

register_deactivation_hook( __FILE__, 'deactivate_display_medium_posts' );



/**

 * The core plugin class that is used to define internationalization,

 * admin-specific hooks, and public-facing site hooks.

 */

require plugin_dir_path( __FILE__ ) . 'includes/class-display-medium-posts.php';



/**

 * Begins execution of the plugin.

 *

 * Since everything within the plugin is registered via hooks,

 * then kicking off the plugin from this point in the file does

 * not affect the page life cycle.

 *

 * @since    1.0.0

 */

function run_display_medium_posts() {



    $plugin = new Display_Medium_Posts();

    $plugin->run();



}

run_display_medium_posts();



    // Example 1 : WP Shortcode to display form on any page or post.

    function posts_display($atts){

         $a = shortcode_atts(array('handle'=>'-1', 'default_image'=>'http://i.imgur.com/p4juyuT.png', 'display' => 3, 'offset' => 0, 'total' => 10, 'list' => false), $atts);

        // No ID value

        if(strcmp($a['handle'], '-1') == 0){

                return "";

        }

        $handle=$a['handle'];

        $default_image = $a['default_image'];

        $display = $a['display'];

        $offset = $a['offset'];

        $total = $a['total'];

        $list = $a['list'];



        $data = file_get_contents_custom("https://medium.com/".$handle."/latest?format=json"); 

        $data = str_replace("])}while(1);</x>", "", $data);



        $json = json_decode($data, true);



        $json = json_decode($data);

        $posts = $json->payload->references->Post;

        $items = array();

        $count = 0;

        foreach($posts as $post)

        {
            echo "<pre>"; print_r ($post); echo "</pre>";
            $items[$count]['title'] = $post->title;
            $items[$count]['url'] = 'https://medium.com/'.$handle.'/'.$post->uniqueSlug;

            $items[$count]['subtitle'] = $post->content->subtitle;
            $items[$count]['latestPublishedAt'] =  $post->latestPublishedAt;

            if(!empty($post->virtuals->previewImage->imageId))

            {

                $image = 'http://cdn-images-1.medium.com/max/500/'.$post->virtuals->previewImage->imageId;

            }

            else {

                $image = $default_image;

            }

            $items[$count]['image'] = $image;

            $items[$count]['duration'] = round($post->virtuals->readingTime);

            $items[$count]['date'] = $post->virtuals->createdAtRelative;



            $count++;

        }

        if($offset)

        {

            $items = array_slice($items, $offset);  

        }



        if(count($items) > $total)

        {

            $items = array_slice($items, 0, $total); 

        }



    ?>

        <div id="display-medium-owl-demo" class="display-medium-owl-carousel">

            <?php
            foreach($items as $item) {
            ?>


            <div class="display-medium-item">



                <?php echo "<span class='display-medium-date'>".$item['date']."</span>"; ?> / <?php echo "<span class='display-medium-readtime'>".$item['duration']."min read</span>"; ?>.
                <a href="<?php echo $item['url']; ?>">


                    <p class="display-medium-title details-title"><?php echo $item['title']; ?></p>

                </a>

                <p class="display-medium-subtitle">

                    <?php echo $item['subtitle']; ?>

                </p>


                <p class="display-medium-read-more">

                    <a href="<?php echo $item['url']; ?>" class="text-right display-medium-readmore">Read More</a>

                </p>

            </div>



            <?php } ?>

        </div>

        <script type="text/javascript">

                function initializeOwl(count) {

                     jQuery(".display-medium-owl-carousel").owlCarousel({

                        items: count,

                        lazyLoad : true,

                      });

                }

        </script>

        <?php

            if(!$list)

            {

                echo '<script>initializeOwl('.$display.');</script>';

            }

        ?>

        <?php

    }

    add_shortcode('display_medium_posts', 'posts_display');

/ .

函数初始值EWL(计数){ jQuery(“.display medium owl carousel”).owlCarousel({ 项目:计数, 懒汉:没错, }); }
为了将所需的历元时间戳转换为人类可读的时间戳,如果使用的是
date()
函数,则需要将历元除以1000。
例如,回音日期('Y-m-d H:i:s',1483582815852/1000)

你能显示翻译日期的代码吗?你确定翻译成十一月吗?通过历元转换器将其显示为Thu,2017年1月5日02:20:15.852 GMT。转换器链接:@bj7:我使用php中的date()函数对其进行了转换。然后您使用的日期错误,1483582815852的日期是:假设此时间戳以毫秒为单位:GMT:Thu,2017年1月5日02:20:15.852 GMT您是否将历元时间戳除以1000<代码>回音日期('Y-m-d H:i:s',1483582815852/1000)给我一月的时间