从m/d/y格式日期转换为Unix时间戳

Anc*_*end 1 php timestamp

我试图想出一种方法来使用PHP将以下格式的任何日期转换为unix时间戳.我想知道是否有人可以帮助我实现这一目标.

这是我尝试过的,但是没有用:

   $expiration_date = '11/22/12';

   $timestamp = strtotime(date("m/d/y", $expiration_date));     
Run Code Online (Sandbox Code Playgroud)

dig*_*rld 6

你不需要这个date()部分.

这样做:

$expires = '11/22/12';
$unix = strtotime($expires);
Run Code Online (Sandbox Code Playgroud)

http://php.net/manual/en/function.strtotime.php

您的示例的问题是您将字符串传递给date()函数.
date()函数需要格式字符串,例如'm/d/y',然后将时间作为int值.
你传给它一个字符串,所以它不起作用.

date():http://php.net/manual/en/function.date.php