在我的 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/