duanping5306 2013-01-24 20:41
浏览 193
已采纳

在PHP中使用时间戳的错误

I am receiving the error: A non well formed numeric value encountered

Here is my code:

<?php

$timestamp= '2013-01-20 18:20:20';

$datetime= date('F j, Y', $timestamp);

    echo $datetime;

?>

This returns January 1, 1970 Which isn't right. What am I doing wrong? BTW: All of my $timestamp variables will be in that format. I am using datetime in my MySQL database table.

Thanks

  • 写回答

2条回答 默认 最新

  • dongling0519 2013-01-24 20:41
    关注

    the date function takes a timestamp which is an int you need to call it using

    date('F j, Y', time());
    

    or

    $timestamp= '2013-01-20 18:20:20';
    date('F j, Y', strtotime($timestamp));
    

    see http://php.net/manual/en/function.date.php for info on how to use the date function

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

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题