如何格式化这个日期(dd / mm / yyyy)到(j M Y)在PHP? [英] How to format this date (dd/mm/yyyy) into (j M Y) in PHP?

查看:83
本文介绍了如何格式化这个日期(dd / mm / yyyy)到(j M Y)在PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将这个日期格式(以PHP为例):dd / mm / yyyy,例如18/08/2011,转换成j MY,应该输出这样的内容,2011年8月18日

I'm trying to convert this date format (in PHP): "dd/mm/yyyy", for example 18/08/2011, into "j M Y" which should output something like this, "18 August 2011".

如果有人可以帮助,这将是非常感激的,
谢谢。

If anyone could help, it would be much appreciated, Thanks.

推荐答案

<?php 
   $str = "18/08/2011";
    preg_match("|(.*?)/(.*?)/(.*?)|", $str, $match);
    $str = $match[2]."/".$match[1]."/".$match[2];
    echo $your_format = date("j M Y", strtotime($str)); //strtotime() expects mm/dd/yyyy
    //returns 18 Aug 2008
?> 

http://sandbox.phpcode.eu/g/29439.php

这篇关于如何格式化这个日期(dd / mm / yyyy)到(j M Y)在PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆