gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:57:55 25 4
gpt4 key购买 nike

在 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 ).


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

关于php - 将日期转换为整数(时间戳),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28406341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com