将DD-MM-YYYY转换为时间(unix)


converting DD-MM-YYYY to time (unix)

有人能告诉我如何将DD-MM-YYY(文本)转换为TIME(unix)吗?我想我会说我在所有页面的顶部都有这一行,以防它意味着不同的代码。

date_default_timezone_set('Europe/London'); //### Set the default timezone

您将需要strtotime(),只要它是DD-MM-YYYY或类似的批准格式。

d-m-y是一种有效的GNU格式。使用

$timestamp = strtotime('1-1-2012');  

如果它已经在SQL中,可以调用数据库的转换方法。MySQL使用UNIX_TIMESTAMP,它应该接受SQL中的有效日期时间类型。

我想这就是您想要的:

$date = "01/06/2012";
list($month, $day, $year) = split('/', $date);
$timeStamp = mktime(0, 0, 0, $month, $day, $year);
echo $timeStamp;

希望能有所帮助。。。

$date_string = "24/12/2017";
echo strtotime(str_replace("/", "-", $date_string)));