php PHP日期转换dd [th/st/rd]/月/yyyy
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13640959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP date conversion dd [th/st/rd] / month / yyyy
提问by Aliya Kcx
I have my users entering the date in this format :- mm/dd/yyyy (11/21/2012)
我让我的用户以这种格式输入日期:- mm/dd/yyyy (11/21/2012)
My PHP script converts the date into the following format :- dd-Month-yyyy (21-November-2012)
我的 PHP 脚本将日期转换为以下格式:- dd-Month-yyyy (21-November-2012)
I do this using :-
我这样做: -
$new_date = date('d-F-Y', strtotime($user_date));
How can I have the date in this format :- 21st November 2012?
我怎样才能获得这种格式的日期:- 21st November 2012?
Thanks
谢谢
回答by hsz
回答by PHP Ferrari
It will output as you expect
它会像你期望的那样输出
$my_date = '2016-01-01';
echo date('F jS, Y', strtotime($my_date));
# January 1st, 2016
while dSwill also prepends 0
而dS也会在前面加上0
echo date('F dS, Y', strtotime($my_date));
# January 01st, 2016
回答by user9187674
$new_date = date('jS F Y', strtotime($date));
S- English ordinal suffix for the day of the month, 2 characters
(st, nd, rdor th. Works well with j)
S- 月份日期的英文序数后缀,2 个字符(st、nd、rd或th。适用于j)
回答by Kiryamwibo Yenusu
You can use something like:
您可以使用以下内容:
echo date('l, F jS');
Or even get a bit fancy with the HTML:
或者甚至对 HTML 有点花哨:
echo date('l, F j<\s\u\p>S</\s\u\p>');
回答by Nikit Barochiya
**My Date = 22-12-1992**
<?php
$mydate = "22-12-1992";
$newDate = date("d M Y", strtotime($mydate));
$new_date = date('dS F Y', strtotime($newDate));
echo $new_date;
?>
**OutPut = 22nd December 1992**
回答by Karan Shaw
$date = date_create('09-22-2012');by this code you will get your desire
echo $date->format('d S F Y');
$date = date_create('09-22-2012');通过这个代码你会得到你的愿望
echo $date->format('d S F Y');
for more you can also visit http://php.net/manual/en/datetime.formats.date.php
有关更多信息,您还可以访问http://php.net/manual/en/datetime.formats.date.php

