[英]PHP Date Format returning incorrect suffix ('S')
I have a Unix Timestamps such as 1423389830
and 1511367992
. 我有Unix时间戳,例如
1423389830
和1511367992
。 I'm using a simple date()
function: date( 'M nS, Y', $timestamp );
我正在使用一个简单的
date()
函数: date( 'M nS, Y', $timestamp );
and it seems like it's returning the wrong date, with the appropriate suffix - which output some rather silly results. 似乎返回了错误的日期,并带有适当的后缀-输出的结果有些愚蠢。
Using the following sample code: 使用以下示例代码:
printf( '[%s] [%s]', date( 'M nS, Y', 1423389830 ), date( 'M nS, Y', 1511367992 ) );
On 3 servers: Mine, PHPTester.net , and OnlinePHPFucntions.com , the result is 在3个服务器上:Mine, PHPTester.net和OnlinePHPFucntions.com ,结果是
[Feb 2th, 2015] [Nov 11nd, 2017]
Dropping those timestamps into EpochConverter.com I get and Sunday, February 8, 2015 2:03:50 AM GMT-08:00
and Wednesday, November 22, 2017 8:26:32 AM GMT-08:00
, respectively. 删除那些时间戳到EpochConverter.com我得到和
Sunday, February 8, 2015 2:03:50 AM GMT-08:00
和Wednesday, November 22, 2017 8:26:32 AM GMT-08:00
,分别。 February's date is 6 days early - and November's is 11 days early. 2月的日期提前6天-11月的日期提前11天。
You can see an example here: http://sandbox.onlinephpfunctions.com/code/605415e0490af3e8e1dc3cf12ce9e1ec9ea2b3b6 您可以在此处看到一个示例: http : //sandbox.onlinephpfunctions.com/code/605415e0490af3e8e1dc3cf12ce9e1ec9ea2b3b6
So, as I wrote out this question, I realized that the day that was output was the same number as the month's number (Feb = 2nd month, November is the 11th month). 因此,当我写下这个问题时,我意识到输出的日期与该月的日期相同(2月= 2月,11月是11月)。
This lead me to look back at my date format and I realized I used the wrong format... the n
should be a d
or j
: date( 'M jS, Y', $timestamp );
这让我回头看了看我的日期格式,我意识到我使用了错误的格式...
n
应该是d
或j
: date( 'M jS, Y', $timestamp );
. 。
I figured I'll leave this for (rather embarrassing) posterity - and hopefully to help anyone who sees their PHP Date Suffix returning humorously incorrect to check their Date Format String and make sure you're actually using the appropriate/desired format 我想我会把这个留给(相当尴尬的)后代使用-希望能帮助看到PHP Date后缀幽默返回错误的任何人检查其Date Format字符串 ,并确保您实际上使用的是适当/所需的格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.