简体   繁体   English

我如何将下面的代码修改为 output 格式为 dmY H:i:s 的日期?

[英]how can i modify the code below to output a date in the the format d-m-Y H:i:s?

how can i modify the code below to output a date in the the format dmY H:i:s我如何将下面的代码修改为 output 格式为 dmY H:i:s 的日期

public function storeFormValues($params)
{

    // Store all the parameters
    $this->__construct($params);

    // Parse and store the publication date
    if (isset($params['publicationDate'])) {
        $publicationDate = explode('-', $params['publicationDate']);

        if (count($publicationDate) == 3) {
            list($y, $m, $d) = $publicationDate;
            $this->publicationDate = mktime(0, 0, 0, $m, $d, $y);
        }
    }
}`

You can do it simply like this你可以像这样简单地做

public function storeFormValues($params)
{

    // Store all the parameters
    $this->__construct($params);

    // Parse and store the publication date
    if (isset($params['publicationDate'])){
        $d = new DateTime($params['publicationDate']);
        echo $d->format('d-m-Y H:i:s');
        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在学说中使用“ dmY H:i:s”日期? - Using “d-m-Y H:i:s” dates with Doctrine? 将具有长精度的 ISO8601 日期时间戳格式化为 dmY H:i:s - Format a ISO8601 datetime stamp with long precision as d-m-Y H:i:s 为什么DateTime :: createFromFormat('dmY H:i A',$ date)-> format('dm-Y')将日期更改为下午1点后的第二天? - Why does DateTime::createFromFormat('d-m-Y H:i A', $date)->format('d-m-Y') change the date to the following day after 1pm? 如何在PHP中以DMY格式按Mysql数据库中的日期列显示并基于它进行搜索 - How Can I Display By Date Column From Mysql Database In D-M-Y Format in PHP And Make Search Based on it PHP:将日期格式 d/m/Y h:i:sa 更改为 m/d/Y h:i:sa - PHP: Change Date format d/m/Y h:i:s a to m/d/Y h:i:s a 使用'dmY H:i:s'时间戳的PHP倒数计时器 - PHP countdown timer using 'd-m-Y H:i:s' timestamp 如何以Ymd H:i:s格式在ORACLE中保存日期? - How to save date in ORACLE in Y-m-d H:i:s format? 如何将日期格式从Ymd转换为dmY? - How to convert date format from Y-m-d to d-m-Y? 如何检查日期字符串是否严格按照d / m / Y格式而不是dmY或Ymd - how to check whether date string is in format strictly in d/m/Y not in d-m-Y or Y-m-d php-从MySQL时间戳列以dmY格式输出日期 - php - Output date in d-m-Y format from MySQL timestamp column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM