重写为丹麦时间/日期


rewrite to Danish time / date

你好,这就是我建立自己的论坛的方式,但这就是我必须将日期"设置"到数据库中的方式,该日期应该是 30-5-2012 应该看起来,但当将其从数据库中提取时,它也应该如何查看。我在 MySQLI 中像这样构建它

这是我在数据库中找到它时的外观

<form action="#" method="post" name="formular" onsubmit="return validerform ()">
            <?php
            if ($stmt = $mysqli->prepare('INSERT INTO `forum` (`title`, `tekst`, `dato`, `id_brugere`) VALUES (?, ?, ?, ?)')) { 
            $stmt->bind_param('ssss', $title, $tekst, $dato, $id_brugere);
            //fra input ting ting..
            $title = $_POST["title"];
            $tekst = $_POST["tekst"];
            $id_brugere = $_SESSION["user_id"];
            $dato = date('d-m-Y');
            $stmt->execute();
            $stmt->close();
            //er der fejl i tilgangen til table..
            } else {
                echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error;
            }
            ?>
        <table border="0">
            <tr>
                <td id="tb-w_a"><p>Title</p></td>
                <td>:</td>
                <td><input type="text" name="title"></td>
            </tr>
        </table>
    <textarea name="tekst" style="width:716px; height:170px;"></textarea><br />
    <input type="submit" value="Opret indhold">
</form>

这是我将其从数据库中取出时的外观

<?php
            if ($stmt = $mysqli->prepare('SELECT id_forum, title, tekst, dato, id_brugere FROM `forum` ORDER BY  `forum`.`id_forum` DESC LIMIT 0 , 30'))
            {
            $stmt->execute();
            $stmt->store_result();
            $stmt->bind_result($id_forum, $title, $tekst, $dato, $id_brugere);
            $count_res = $stmt->num_rows;
            if($count_res > 0)
            {
            while ($stmt->fetch()) {    
            ?>
            <tr class="forumtoppen">
            <td class="titleforum"><?php echo $title;?> - <a href="">L&#230;se mere</a></td>
            <td>Dato: <?php echo $dato;?></td>
            </tr>
            <?php
                }
                }
            else
                {
                ?>
                    <p>der er ingen overhovedet!.. hmm</p>
                <?php
                }
            }
            ?>

在这里,我像这样建立它,必须转换为丹麦时间。

<?php echo $dato;?>

不会有错误,但我只需要将其构建到丹麦日期。

为什么不在检索查询中使用MySQL的date_format函数呢?(PHP文档)

SELECT id_forum, title, tekst, date_format(dato,'%d-%m-%Y') as dato, id_brugere 
FROM `forum` 
ORDER BY  `forum` . `id_forum` DESC LIMIT 0 , 30