<分区>
我有这个字符串:“13/10 15:00”,我想将它转换为时间戳,但是当我这样做时:
$timestamp = strtotime("13/10 15:00");
它返回一个空值。
<分区>
我有这个字符串:“13/10 15:00”,我想将它转换为时间戳,但是当我这样做时:
$timestamp = strtotime("13/10 15:00");
它返回一个空值。
最佳答案
在您的代码中,strtotime()
试图将 13/10
转换为第 13 个月的第 10 天,这会返回错误。
如果要解析具有自定义格式的日期字符串,最好改用 DateTime::createFromFormat():
$dtime = DateTime::createFromFormat("d/m G:i", "13/10 15:00");
$timestamp = $dtime->getTimestamp();
关于php - 将此字符串转换为时间戳 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19346858/
相关文章:
php 5.3/mysql : why doesn't apache see mysql?
PHP:使用给定的字段顺序按比 1 级维度值更深的维度值对多数组进行排序
python - Postgres DateTimeField 时间不正确
javascript - 无法在 jQuery 函数中返回 $.posted php 文件数据
php - Wordpress woocommerce 删除购物车
java - Java是否足够长以以毫秒为单位存储纪元时间?
PHP strtotime() "first monday february"如果 2 月 1 日是星期一,则返回第二个星期一