php strtotime not working(php strtotime不工作)
问题描述
所以我使用 strtotime 将此字符串转换为时间戳:
so I converted this string to timestamp using strtotime:
strtotime("1 Nov, 2001");
导致时间戳为 1320177660
which results into the timestamp 1320177660
但是当我尝试使用在线时间戳转换器再次将 1320177660 转换为正常的日期格式时,年份最终是 2011 年而不是 2001 年...
but then when I tried converted 1320177660 into a normal date format again using an online timestamp converter, the year ended up being 2011 rather than 2001...
我做错了什么?
推荐答案
正如@Evan Mulawski 的评论所说,2001"被解释为时间,而不是年份.去掉逗号让PHP将2001"解释为年份:
As @Evan Mulawski's comment says, the "2001" is being interpreted as the time, not the year. Take out the comma to get PHP to interpret the "2001" as a year:
<?php
$ts = strtotime("1 Nov 2001");
echo $ts . "
";
$st = strftime("%B %d, %Y, %H:%M:%S", $ts);
echo $st . "
";
?>
输出:
1004590800
2001 年 11 月 1 日 00:00:00
1004590800
November 01, 2001, 00:00:00
这篇关于php strtotime不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php strtotime不工作


基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01