Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否将mm dd yy格式转换为unix时间戳?_Php_Unix_Timestamp - Fatal编程技术网

Php 是否将mm dd yy格式转换为unix时间戳?

Php 是否将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

我在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}\-[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的问题。您可能已经阅读了文档,其中包含指向的链接,并表示推荐使用。为什么不遵循这一建议?这将花费不到几个小时的时间。你的例子很好