php 日期格式返回 01-01-1970

标签 php mysql date

在我的 php 代码中,我在数据库中插入了一些数据。其中之一是日期。我想以 27-08-2016 的格式显示,但我返回 01-01-1970

这是我的代码。

<?php 
include("./init.php");

if(isset($_POST['submit'])){

 $post_game = $_POST['game'];

 $time = strtotime($_POST['date']);

 $post_date = date("d-m-Y", strtotime($time));

if($post_game==''){

    echo "<script>alert('Please fill in all fields')</script>";
    exit();
    }
else {

    $insert_game = "insert into last_game (game,date) values ('$post_game','$post_date')";

    $run_posts = mysqli_query($con,$insert_game); 

        echo "<script>alert('Post Has been Published!')</script>";

        echo "<script>window.open('index.php?last_game_details','_self')   
   </script>";

     }

   }

?> 

关键的一行是:

 $post_date = date("d-m-Y", strtotime($time));

我的 php 版本是:5.6.23

最佳答案

 $time = strtotime($_POST['date']);
    ^-integer             ^---string

$post_date = date("d-m-Y", strtotime($time));
                                ^^^^^^^---useless duplicate call, since you JUST did this anyways

关于php 日期格式返回 01-01-1970,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38441306/

相关文章:

javascript - 变量赋值给输入值

php - 在没有互联网连接的情况下注册 Android 应用程序

php - Substr 将最后一个字符显示为?

php - 使用 PHP/Laravel 查询循环

MySQL新用户权限不起作用

php - 如何使用php在mysql中插入今天的日期

java - 比较转换 ISO8601 兼容日期与 Java 日期?

hibernate - HQL 中的日期操作

php - 从日期字符串获取月、日、年的最快方法

ruby-on-rails - Rails : Set config. time_zone 到服务器的时区?