var_dump(strtotime('1441185010'));//输出bool(false)var_dump(strtotime('1451382400'));//输出int(13591003898)
很奇怪,为什么这两个的结果不一样呢?
回复讨论(解决方案)
我PHP5.6返回两个false,你的PHP是什么版本。
我PHP5.6返回两个false,你的PHP是什么版本。
我是PHP Version 5.3.3,centos6.4 64位虚拟机,第一个正常输出false,第二个就不对了。
实在奇怪到底是什么问题引起的
不知道你要用来干嘛?
strtotime是将任何英文文本的日期时间描述解析为 Unix 时间戳
echo strtotime('2015/12/11');
如果你要把时间戳转换为日期,用date啊
不知道你要用来干嘛?
strtotime是将任何英文文本的日期时间描述解析为 Unix 时间戳
echo strtotime('2015/12/11');
如果你要把时间戳转换为日期,用date啊
modifier.date_format.php
function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null){ if (substr(PHP_OS,0,3) == 'WIN') { $_win_from = array ('%e', '%T', '%D'); $_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y'); $format = str_replace($_win_from, $_win_to, $format); } if($string != '') { return strftime($format, smarty_make_timestamp($string)); } elseif (isset($default_date) && $default_date != '') { return strftime($format, smarty_make_timestamp($default_date)); } else { return; }}
shared.make_timestamp.php
function smarty_make_timestamp($string){ if(empty($string)) { $string = "now"; }/** 这个判断是我做的一个临时救急解决方案,并没有找到实际原因。 if(strlen((int)$string)==10){ return (int)$string; }*/ $time = strtotime($string);//此处在处理时间戳的时候发现问题里第一个时间戳正常返回false,但是第二个却返回一个不知道怎么得出来的整型,结果与$string不一致,结果自然不对 if (is_numeric($time) && $time != -1) return $time; // is mysql timestamp format of YYYYMMDDHHMMSS? if (preg_match('/^\d{14}$/', $string)) { $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2), substr($string,4,2),substr($string,6,2),substr($string,0,4)); return $time; } // couldn't recognize it, try to return a time $time = (int) $string; if ($time > 0) return $time; else return time();}
我在使用smarty模板格式化时间的时候,使用这种{$aList[list].inputtime|date_format:"%Y-%m-%d %H:%M:%S"},但是这个时间出现错误,在进一步跟踪错误的过程中发现是smarty是直接把时间戳当做字符串交个一个函数处理,这个函数smarty_make_timestamp内部使用strtotime直接处理该字符串,根据处理结果返回不同值。结果却是部分正确,部分错误,貌似时间分界点是以2015-9-4号,所以很奇怪。
echo date('Y-m-d H:i:s', 1441185010); //2015-09-02 17:10:10
可知 1441185010 是有效的时间戳
strtotime -- 将任何英文文本的日期时间描述解析为 Unix 时间戳
如果你 $time = strtotime($string);
而 $string 不是 英文文本的日期时间描述 的话,那自然是错误的了
echo date('Y-m-d H:i:s', strtotime('20150902171010')); //2015-09-02 17:10:10
echo date('Y-m-d H:i:s', strtotime('20150902')); //2015-09-02 00:00:00
你的 1441185010 是否能解释成 1441 年 18 月 50 日 10 时 ????
echo date('Y-m-d H:i:s', 1441185010); //2015-09-02 17:10:10
可知 1441185010 是有效的时间戳
strtotime -- 将任何英文文本的日期时间描述解析为 Unix 时间戳
如果你 $time = strtotime($string);
而 $string 不是 英文文本的日期时间描述 的话,那自然是错误的了
echo date('Y-m-d H:i:s', strtotime('20150902171010')); //2015-09-02 17:10:10
echo date('Y-m-d H:i:s', strtotime('20150902')); //2015-09-02 00:00:00
你的 1441185010 是否能解释成 1441 年 18 月 50 日 10 时 ????
echo date('Y-m-d H:i:s', 1451382400);
//输出2015-12-29 17:46:40
echo date('Y-m-d H:i:s', strtotime('1451382400'));
//输出2400-09-06 14:51:38
echo date('Y-m-d H:i:s', 1441185010); //2015-09-02 17:10:10
可知 1441185010 是有效的时间戳
strtotime -- 将任何英文文本的日期时间描述解析为 Unix 时间戳
如果你 $time = strtotime($string);
而 $string 不是 英文文本的日期时间描述 的话,那自然是错误的了
echo date('Y-m-d H:i:s', strtotime('20150902171010')); //2015-09-02 17:10:10
echo date('Y-m-d H:i:s', strtotime('20150902')); //2015-09-02 00:00:00
你的 1441185010 是否能解释成 1441 年 18 月 50 日 10 时 ????
我的情况跟直接输出不太一样,我这的情况是根据strtotime的结果来判断是直接返回时间戳还是返回经过strtotime处理过的时间,正常strtotime处理时间戳是返回false的,但是我的情况是部分返回false,比如1441185010,但是1451382400返回的就不是false了。
由于你传递给 strtotime 的是是时间戳,所以即便不是 false 也是不对的
echo date('Y-m-d H:i:s', 13591003898); //1992-05-17 19:26:50
由于你传递给 strtotime 的是是时间戳,所以即便不是 false 也是不对的
echo date('Y-m-d H:i:s', 13591003898); //1992-05-17 19:26:50
好吧,版主,先谢谢你。
我之前说过哦,我的情况并不是直接输出的,而是根据strtotime返回的结果在用date输出。
我现在的问题是为什么
strtotime('1441185010')
是false;
而
strtotime('1451382400')
却不是false,理论上讲strtotime(10位时间戳)不应该输出false的吗?
那是你的 php 有问题
经测试都是 false
那是你的 php 有问题
经测试都是 false
经测试确实是php版本的问题,5.3的版本出现上述问题,5.4的版本都是false,只是不知这到底是原因?
5.2的版本同样有上述问题,不清楚这到底是bug还是什么
楼主你去看看这个帖子。。。。http://bbs.csdn.net/topics/391822092

phpisusedforsendendemailsduetoitsignegrationwithservermailservicesand andexternalsmtpproviders,自动化notifications andMarketingCampaigns.1)设置设置yourphpenvironcormentswironmentswithaweberswithawebserverserverserverandphp,确保themailfunctionisenabled.2)useabasicscruct

发送电子邮件的最佳方法是使用PHPMailer库。1)使用mail()函数简单但不可靠,可能导致邮件进入垃圾邮件或无法送达。2)PHPMailer提供更好的控制和可靠性,支持HTML邮件、附件和SMTP认证。3)确保正确配置SMTP设置并使用加密(如STARTTLS或SSL/TLS)以增强安全性。4)对于大量邮件,考虑使用邮件队列系统来优化性能。

CustomHeadersheadersandAdvancedFeaturesInphpeMailenHanceFunctionalityAndreliability.1)CustomHeadersheadersheadersaddmetadatatatatataatafortrackingandCategorization.2)htmlemailsallowformattingandttinganditive.3)attachmentscanmentscanmentscanbesmentscanbestmentscanbesentscanbesentingslibrarieslibrarieslibrariesliblarikelikephpmailer.4)smtppapapairatienticationaltication enterticationallimpr

使用PHP和SMTP发送邮件可以通过PHPMailer库实现。1)安装并配置PHPMailer,2)设置SMTP服务器细节,3)定义邮件内容,4)发送邮件并处理错误。使用此方法可以确保邮件的可靠性和安全性。

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

使用依赖注入(DI)的原因是它促进了代码的松耦合、可测试性和可维护性。1)使用构造函数注入依赖,2)避免使用服务定位器,3)利用依赖注入容器管理依赖,4)通过注入依赖提高测试性,5)避免过度注入依赖,6)考虑DI对性能的影响。

phperformancetuningiscialbecapeitenhancesspeedandeffice,whatevitalforwebapplications.1)cachingwithapcureduccureducesdatabaseloadprovesrovesponsemetimes.2)优化

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

Dreamweaver Mac版
视觉化网页开发工具