dongshuo2752 2010-02-13 16:29
浏览 37
已采纳

PHP日期格式问题

I'm trying to format some dates in PHP (i'm a Coldfusion programmer, so the syntax is similar, but i'm stuck!).

The dates are formatting perfectly into the display I want. However, they all return 1st Jan 1970.

Can anyone shed any light on this?

For background, I am pulling a date from a datetime column in mySQL. The raw date i'm trying to format is....

2010-04-03 00:00:00

Here is the line of code i'm using....

$xml_output .= "\t\t<eventdate>" . date("l jS F", $row['event_date']) . "</eventdate>
";

I want it to display as: Saturday 3rd April

Any help would be appreciated!

Simon

  • 写回答

5条回答 默认 最新

  • duanpan3166 2010-02-13 16:31
    关注

    The second parameter to date() needs to be a UNIX timestamp.

    Convert your date string it into a timestamp first using strtotime():

    $timestamp = strtotime($row["event_date"]);
    echo date("l jS F", $timestamp); // Saturday 3rd April 
    

    Manual pages:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器