在dd/mm/YYYY格式上使用strtotime的问题


Issue with using strtotime on dd/mm/YYYY format

我正试图找出两个日期之间的差异。然而,我遇到了将日期转换为UNIX代码的第一个障碍。

以下是我正在尝试的:

    $endTimeStamp = strtotime(get_post_meta( $the_query->post->ID, 'wedding_date', true ));

然而,如果我只是这样做,它什么也不返回:

echo get_post_meta( $the_query->post->ID, 'wedding_date', true );

我收到以下日期:2015年12月26日(即2015年12日26日)

我的strtotime()函数在这个日期不起作用是有原因的吗?

问题:

然而,我遇到了将日期转换为UNIX代码的第一个障碍。

解决方案:

要获取unix时间戳,可以执行以下操作:

$unixdatetime = DateTime::createFromFormat('d/m/Y', get_post_meta( $the_query->post->ID, 'wedding_date', true ))->getTimestamp();
echo $unixdatetime;