Home > php教程 > php手册 > body text

PHP自定义日期英文格式 Feb 11,2015

WBOY
Release: 2016-06-06 19:44:46
Original
1981 people have browsed it

背景:[PHP小工具]项目中,经常会要求多版本语言支持,而日期也是必不可少的组成元素。 英文日期书写顺序分英式和美式,举例如。 美国:月 日 年( January 8th,2014 或 January 8,2014 ) 英国:日 月 年( 8th January,2014 或 8 January,2014 ) 那么,接

背景:[PHP小工具]项目中,经常会要求多版本语言支持,而日期也是必不可少的组成元素。

  英文日期书写顺序分英式和美式,举例如。

  美国:月年(January 8th,2014 January 8,2014

  英国:日年(8th January,2014 8 January,2014

  那么,接下来分享一个日期转换的工具函数getMyDate,使用"January 8,2014"格式,如有需要可以自行扩展。

 

PHP:class.util.php

class Util {
    public static function getMyDate($d){        
        $marr=array('January','February','March','April','May','June','July','August','September','October','November','December');
        $stamp = strtotime($d);
        $m = date('m',$stamp);        
        return substr($marr[$m-1], 0,3).' '.date('d',$stamp).', '.date('Y',$stamp); --截取数组元素的前三个字符
    }
}

 

调用:

$time = date('Y-m-d G:i:s');
echo Util::getMyDate($time);

 

总结:天天都有所斩获,每天前进一小步,累计一点一滴,是生活中动力的源泉,也是成功的关键。

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!