gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:11:38 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com