将日期转换为整数(时间戳)

Convert date to integer (timestamp)

在 mysql 中,data typeinteger... 我想将日期保存为 1422104820 格式(timestamp).

$Date = $_POST['Date'];
$Time = $_POST['myTime'];
$Date1 = $Date.$myTime;

insert into table ('date') values ($Date1);

您搜索的函数是strtotime();

您可以使用这两种方式之一来获取 timestamp:

方法 #1:结构化风格。

// Use the strtotime() function
$timestamp = strtotime($Date1);

方法 #2:面向对象的风格。

// DateTime class.
$date = new DateTime($Date1);
$timestamp = $date->getTimestamp();

NOTE ABOUT PERFORMANCE:

The structured style ( strtotime() ) is faster than the Object-oriented style ( DateTime ).


您可以在此处查看这两种获取 timestamp 的方式的有趣基准:
http://en.code-bude.net/2013/12/19/benchmark-strtotime-vs-datetime-vs-gettimestamp-in-php/