如何从例如22-09-2008中获取时间戳?


当前回答

$time = '22-09-2008';
echo strtotime($time);

其他回答

<?php echo date('M j Y g:i A', strtotime('2013-11-15 13:01:02')); ?>

http://php.net/manual/en/function.date.php

使用PHP函数strtotime()

echo strtotime('2019/06/06');

date -格式化本地时间/日期

还有strptime(),它只需要一种格式:

$a = strptime('22-09-2008', '%d-%m-%Y');
$timestamp = mktime(0, 0, 0, $a['tm_mon']+1, $a['tm_mday'], $a['tm_year']+1900);

警告:

Windows系统不支持该功能 该函数在PHP 8.1.0中已弃用。非常不鼓励依赖这个函数。

<?php echo date('U') ?>

如果你愿意,把它放在一个MySQL输入类型时间戳中。上面的代码运行得很好(仅适用于PHP 5或更高版本):

<?php $timestamp_for_mysql = date('c') ?>

使用strtotime()函数,您可以轻松地将日期转换为时间戳

<?php
// set default timezone
date_default_timezone_set('America/Los_Angeles');

//define date and time
$date = date("d M Y H:i:s");

// output
echo strtotime($date);
?> 

更多信息:http://php.net/manual/en/function.strtotime.php

在线转换工具:http://freeonlinetools24.com/