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

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

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

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
