[英]PHP Datetime->format returning wrong ordinal suffix
I have a UTC time string that is not playing nice with PHP's DateTime->format
function. 我有一个UTC时间字符串,无法与PHP的
DateTime->format
函数配合使用。
I create a new php file and paste in the following: 我创建一个新的php文件并粘贴到以下文件中:
<?php
$date = DateTime::createFromFormat('U', 1567209600, new DateTimeZone('Australia/Brisbane') );
die( $date->format( 'l, nS F Y' ) );
I am getting: 我正进入(状态:
Saturday, 8st August 2019
For starters, the correct date is 31, and the ordinal suffix for 8 should be 'th'. 对于初学者,正确的日期是31,序号后缀8应该是'th'。 What is actually going on here?
这到底是怎么回事? There is no other code in this file.
该文件中没有其他代码。
Note the codes are case sensitive. 请注意,代码区分大小写。
N
is ordinal day of the week and n
is the ordinal month. N
是星期几, n
是星期几。 You want j
, which is day of the month without leading zeroes: l, jS FY
您想要
j
,这是一个不带前导零的月份中的某天: l, jS FY
$date = DateTime::createFromFormat('U', 1567209600, new DateTimeZone('Australia/Brisbane') );
var_dump($date);
The time zone is not set correctly. 时区设置不正确。
Output 输出量
object(DateTime)#2 (3) { ["date"]=> string(26) "2019-08-31 00:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" }
If the date was created from a timestamp, the time zone is always UTC. 如果日期是根据时间戳创建的,则时区始终为UTC。 You must use setTimeZone after create to transfer to your time zone.
创建后必须使用setTimeZone才能转移到您的时区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.