首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >前端添加当前日期不起作用

问前端添加当前日期不起作用
EN

Stack Overflow用户
提问于 2018-09-13 12:15:47
回答 2查看 266关注 0票数 0

我使用acf_form()函数在前端添加/更新posts。除了邮寄日期外,一切都很顺利。不知何故,它发布了一个非常古老的日期(1970/01/01)。我想把现在的日期改过来。这是我的代码:

代码语言:javascript
复制
    $current_datetime = date('Y-m-d H:i:s');
    acf_form_head();
    acf_form(array(
        'post_id'       => 'new_post',
        'post_title'    => true,
        'post_content'  => true,
        'submit_value'  => __("Send", 'acf'),
        'updated_message' => __("Suksess!", 'acf'),
        'new_post'      => array(
            'post_type'     => 'nyhet',
            'post_status'   => 'publish',
            'post_author'   => get_current_user_id(),
            'post_category' => '',
            'post_modified' => $current_datetime,
            'post_modified_gmt' => $current_datetime,
        ),
        'fields'        => array('ingress', 'publisere_kun_pa_lokallagssiden', 'featured_image'),
        'html_submit_button' => '<input type="submit" class="button box-button green save-content" value="%s" />',
    ));

我知道,如果是当前日期,我不需要设置'post_modified‘和'post_modified_gmt’值。我尝试了没有这2,然后我尝试手动设置当前日期时间。但它总是插入那个奇怪的老约会。我在更新帖子方面也有同样的问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-09-13 13:01:03

WordPress有许多日期/时间函数

Time

你应该需要:

代码语言:javascript
复制
acf_form_head();
acf_form(array(
    'post_id'       => 'new_post',
    'post_title'    => true,
    'post_content'  => true,
    'submit_value'  => __("Send", 'acf'),
    'updated_message' => __("Suksess!", 'acf'),
    'new_post'      => array(
        'post_type'     => 'nyhet',
        'post_status'   => 'publish',
        'post_author'   => get_current_user_id(),
        'post_category' => '',
        'post_modified' => current_time( 'mysql' ),
        'post_modified_gmt' => current_time( 'mysql' ),
    ),
    'fields'        => array('ingress', 'publisere_kun_pa_lokallagssiden', 'featured_image'),
    'html_submit_button' => '<input type="submit" class="button box-button green save-content" value="%s" />',
));

欲了解更多信息:

time/

票数 2
EN

Stack Overflow用户

发布于 2018-09-13 12:53:06

看来1970/01/01是你的系统日期。看看你的配置。

http://php.net/manual/en/function.date.php

函数date使用给定的整数时间戳返回根据给定格式字符串格式化的字符串,如果没有给出时间戳,则返回当前系统时间。换句话说,时间戳是可选的,默认为time()的值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52313568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档