mysql里面有张表,表里面有字段名位time,字段类型为date
有记录为:2011-02-01
现在先通过php把2011-02-01转换成2011/02/01
现在通过php读取出来,得到echo $row['time'];  //输出2011-02-01
echo str_replace('-','/',$row[rjrq]);//输出2011/02/01
echo date('Y/m/d',strtotime($row['rjrq'])); //输出居然是1970/01/01,应该输出2011/02/01才对
echo date('Y/m/d',$row['rjrq']); //输入居然还是1970/01/01,应该输出2011/02/01才对为什么date('Y/m/d',strtotime($row['rjrq'])) 与date('Y/m/d',$row['rjrq']) 都没有成功
难道要转成2011/02/01只能通过str_replace或者substr吗

解决方案 »

  1.   

    echo date('Y/m/d',strtotime('2011-02-01'));
      

  2.   

    首先谢谢foolbirdflyfirst,我也知道echo date('Y/m/d',strtotime('2011-02-01'));是可以的,可是我的数据是从数据表提取出来的,也就是$row['rjrq'],
    echo $row['rjrq'];//会输出2011-02-01
    可是date('Y/m/d',strtotime($row['rjrq']))就是不成功,什么原因
      

  3.   

    在php处理时需要加个时区的代码
      

  4.   

    date_default_timezone_set('Asia/Shanghai');
    $time = $row['rjrq'];
    date('Y/m/d',strtotime($time));
      

  5.   

    mysql里面有张表,表里面有字段名位time,字段类型为date
    echo $row['time'];  //输出2011-02-01
    echo str_replace('-','/',$row[rjrq]);//输出2011/02/01你的表中难道有两个相同内容的字段吗?