在 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 ));

它 returns 没什么,但是,如果我只是这样做:

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

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

我的 strtotime() 函数无法处理该日期是否有原因?

问题:

However I'm stuck at the first hurdle with converting my date to a UNIX code.

解法:

要获取 unix 时间戳,您可以这样做:

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