Create user-friendly date in PHP

给你一囗甜甜゛ 提交于 2019-12-13 03:55:25

问题


System returns me that date 20110408.

Is it possible to covert it to 8 April 2011? I'm using PHP5. Can't figure out how to do that with DateTime class.


回答1:


date function <--

$original_date = '20110408';
date('d F Y', strtotime($original_date));



回答2:


try these

echo date("Y-m-d H:i:s")."<br />";
echo date("F j, Y")."<br />";
echo date("j F Y")."<br />";



回答3:


You can use:

date("j F Y", strtotime('20110408'));



回答4:


You could always use:

function formatDate($date) {
    // 20110408 -> 8 April 2011
    $months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
    $year = substr($date, 0, 4);
    $month = $months[intval(substr($date, 4, 2))-1];
    $day = (int)substr($date, -2);
    return sprintf("%d %s %d", $day, $month, $year);
}

I hope that's not too easy!



来源:https://stackoverflow.com/questions/5919387/create-user-friendly-date-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!