Php 是否将mm dd yy格式转换为unix时间戳?
我在google和Stack Exchange上花了几个小时。就我的一生而言,我还没有找到一个有效的解决办法,我也不知道为什么 我只需要将06-15-14格式化并放入unix时间戳。我试过各种各样的东西。mktime、strptime、strto……通常没有任何东西吐出来,或者我得到12-31-69 我还需要得到个位数的日期,如-6-15-14或6-5-14Php 是否将mm dd yy格式转换为unix时间戳?,php,unix,timestamp,Php,Unix,Timestamp,我在google和Stack Exchange上花了几个小时。就我的一生而言,我还没有找到一个有效的解决办法,我也不知道为什么 我只需要将06-15-14格式化并放入unix时间戳。我试过各种各样的东西。mktime、strptime、strto……通常没有任何东西吐出来,或者我得到12-31-69 我还需要得到个位数的日期,如-6-15-14或6-5-14 $chance = "come on 06-15-14"; if (preg_match("/[0-9]{1,2}\-[0-9]{1,2
$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);
这似乎解决了您正在使用strtime的问题。您可能已经阅读了文档,其中包含指向的链接,并表示推荐使用。为什么不遵循这一建议?这将花费不到几个小时的时间。你的例子很好