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

时间:2014-06-18 22:45:20

标签: php unix timestamp

我在Google和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";
}

2 个答案:

答案 0 :(得分:0)

假设你的正则表达式是正确的,

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

应该是

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

没有引号

答案 1 :(得分:0)

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

似乎解决了这个问题