在 mysql 中,数据类型
是整数
...我想将日期保存为1422104820
格式(时间戳)。
$Date = $_POST['Date'];
$Time = $_POST['myTime'];
$Date1 = $Date.$myTime;
insert into table ('date') values ($Date1);
最佳答案
您可以使用这两种方法之一来获取时间戳
:
方法#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
).
您可以在此处查看这两种获取时间戳的方法的有趣基准:
http://en.code-bude.net/2013/12/19/benchmark-strtotime-vs-datetime-vs-gettimestamp-in-php/
关于php - 将日期转换为整数(时间戳),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28406341/