2016-07-18 06:25 阅读 49

php转换日期格式手动dd / mm / yyyy [复制]

This question already has an answer here:

Use date()

$sqldate = "2016-07-18";
$newDate = date("d-m-Y",$sqldate);

I also use

implode('-', array_reverse(explode('/', $sqldate)));

I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in SQL); however I don't know how the date function requires a timestamp, and I can't get a timestamp from this string.

I am getting particular date format. WHY? I tried get a date expected format, i tried php date but no success..

I excpected output

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    dongmei2957 dongmei2957 2016-07-18 06:27

    Use strtotime().

    $sqldate = "2016-03-21";
    echo $newDate = date("d/m/Y",  strtotime($sqldate));



    Live Demo : Click Here

    点赞 评论 复制链接分享
  • doupu1949 doupu1949 2016-07-18 06:27
    $sqldate = "2016-03-21";
    $newDate = date("d-m-Y",strtotime($sqldate));

    this is what you need.

    点赞 评论 复制链接分享
  • duanbinmi8970 duanbinmi8970 2016-07-18 06:28
     $sqldate = "2016-03-21";
     echo date('d/m/Y', strtotime($sqldate));
    点赞 评论 复制链接分享