简体   繁体   English

简单的PHP日期问题

[英]Simple PHP date question

I have the following string: 我有以下字符串:

$date = 2011-08-29 14:53:15;

when I do this: 当我这样做时:

echo date('F j, Y', $date);

I get December 31, 1969 instead of August 29, 2011. How to get the right date? 我得到的是1969年12月31日,而不是2011年8月29日。如何获得正确的日期?

$date值上使用strtotime

echo date('f j, Y',strtotime($date));
<?php
   $date = strtotime($date);
   echo date('F j, Y', $date);
?>

To explain... 解释...

The function date() is expecting a unix time-stamp (something like 23498034). 函数date()期望使用unix时间戳(类似于23498034)。 the function strtotime() takes a normal looking date that a person would make, and converts it to a timestamp. 函数strtotime()获取一个人会看到的正常观看日期,并将其转换为时间戳。 Then you're good to go. 那你很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM