简体   繁体   English

从strtotime转换为日期

[英]Convert from strtotime into date

Im trying to convert the timestamp into a date: 我正在尝试将时间戳转换为日期:

echo '<td>' . strtotime(mysql_result($result,$i,"datum_overboeking")) = date('d-m-Y'). '</td>';

This gives me an error: Fatal error: Can't use function return value in write context 这给我一个错误:致命错误:不能在写上下文中使用函数返回值

I want the strtotime output do an input in the date ('dm-y') so it will output the given date format. 我希望strtotime输出在日期('dm-y')中进行输入,以便输出给定的日期格式。

update: 更新:

Perfect it works, thanks ! 完美的作品,谢谢!

But how can you find this way of correct syntax construction because Im always struggling how to correctly build up a syntax like this ? 但是,由于Im一直在努力正确地构建这样的语法,您如何找到这种正确的语法构建方式?

Use the second parameter of the date function. 使用日期函数的第二个参数。

date('d-m-Y', strtotime(mysql_result($result,$i,"datum_overboeking")));

look at the date function 看日期功能

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

Maybe you can use something like this: 也许您可以使用如下所示的内容:

     <?php
    $overboeking = mysql_result($result,$i,"datum_overboeking");

    try {
        $date = new DateTime($overboeking);
    } catch (Exception $e) {
        echo $e->getMessage();
        exit(1);
    }

    echo '<td>'.$date->format('d-m-Y').'</td>';
    ?>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM