将mm-dd-yy格式转换为unix时间戳


Convert mm-dd-yy format to unix time stamp?

我花了几个小时在谷歌和Stack Exchange上。就我的一生而言,我还没有找到一个有效的解决方案,我也不知道为什么。

我只需要将06-15-14格式化并放入unix时间戳中。我试过各种各样的东西。mktime、strptime、strto。。。通常没有吐出任何东西,或者我得到12-31-69

我还需要获得个位数的日期IE-6-15-14或6-5-14

$chance = "come on 06-15-14";
if (preg_match("/[0-9]{1,2}'-[0-9]{1,2}'-[0-9][0-9]/", $chance, $matches)) {
echo "Match was found <br />";
echo $matches[0];

$a = strptime('$matches[0]', '%m-%d-%y');
echo $a;

}
else {
echo "nope";
}

假设正则表达式正确,

$a = strptime('$matches[0]', '%m-%d-%y');

应该是

$a = strptime($matches[0], '%m-%d-%y');

没有引号

 list($month, $day, $year) = split('-', $matches[0]);
 $timestamp = gmmktime(0, 0, 0, $month, $day, $year);

这似乎解决了的问题