dongmi8980 2014-03-19 16:11
浏览 24
已采纳

PHP:在Localhost上将日期转换为单词

I extracted a date out of a MySQL database:

echo $nextup['date'] 

which is echoed as an DATETIME:

2014-03-19 15:21:42

Now, I'd like to convert/cast this to a readable form:

19 March 2014 15:21:42

but I couldn't find how. I've read the date/time manual for PHP but it doesn't say how to convert.

Thanks in advance!

  • 写回答

4条回答 默认 最新

  • douhuangzhi0707 2014-03-19 16:15
    关注

    Try strtotime and date combination:

    function translate_names($eng) {
        $names = array (
          'Januari' => 'January',
          'Februari' => 'February',
          'Maart' => 'March',
          'April' => 'April',
          'Mei' => 'May',
          'Juni' => 'June',
          'Juli' => 'July',
          'Augustus' => 'August',
          'September' => 'September',
          'Oktober' => 'October',
          'November' => 'November',
          'December' => 'December',
    );
    
        return array_search($eng, $names);
    }
    
    $date = $nextup['date'];
    $month = addcslashes(translate_names(date('F', strtotime($date))), 'a..zA..Z');
    
    $string = "d $month Y H:i:s";
    echo date($string, strtotime($date));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大