kri*_*mar 2 php date date-format
我尝试使用以下代码将日期格式从 dmy 更改为 ymd,但是在使用时我得到了错误的日期。
我的代码
$sdate11=date("Y-m-d", strtotime($_POST["txtstartdates"]) );
$sdate111=date("Y-m-d", strtotime($_POST["txtenddates"]) );
Run Code Online (Sandbox Code Playgroud)
插入的日期是
30-05-2013 and 31-05-2013
Run Code Online (Sandbox Code Playgroud)
它返回的日期是
2035-11-03 and 2036-11-02
Run Code Online (Sandbox Code Playgroud)
你能帮我找出这里的问题并解决它吗
谢谢你。
尝试像分裂一样
$a = split('-',$_POST["txtstartdates"]);
Run Code Online (Sandbox Code Playgroud)
或者你可以使用爆炸甚至像
$a = explode('-',$_POST["txtstartdates"]);
$my_new_date = $a[2].'-'.$a[1].'-'.$a[0];
Run Code Online (Sandbox Code Playgroud)
这里 strtotime 不适用于 dd-mm-yyyy 格式