惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
T
Threatpost
C
CERT Recently Published Vulnerability Notes
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
Project Zero
Project Zero
H
Heimdal Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
Google Online Security Blog
Google Online Security Blog
W
WeLiveSecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News | PayPal Newsroom
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
L
LINUX DO - 热门话题
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
V
Vulnerabilities – Threatpost
Hacker News: Ask HN
Hacker News: Ask HN
S
Securelist
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
NISL@THU
NISL@THU
N
News and Events Feed by Topic
S
Security Affairs
The Last Watchdog
The Last Watchdog
T
Tor Project blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tenable Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security

博客园 - meil

C#下取得Exif中照片拍摄日期 DotNet中人民币符号的输出 BAT实现照片文件批量改名 Wicket中JQuery事件绑定失效的解决 软件开发中的完整测试所包括的环节UT、IT、ST、UAT Eclipse中SVN插件的安装方式 从mysql中导出单个表结构和数据 代码帝:一个月10万行代码 Android开发调试工具ADB的使用 Android系统权限配置 Android程序开发基础之——页面传值 Android程序开发基础之——页面布局 Android程序开发的环境配置 SQLServer2008 动态SQL实践 ASP.net中实现双表格同步缩放不变形 Javascript实现DIV滚动自动滚动到底部 SQL Server 日期格式转换示例大全 TinyMCE使用手册 LINQ中的OrderBy实现多字段升序、降序排序实现
PHP中使用mktime获取时间戳的一个黑色幽默
meil · 2012-05-30 · via 博客园 - meil
mktime(hour,minute,second,month,day,year,is_dst)这是mktime的语法说明,一目了然应该不难写出一个时间戳的代码来!

下面这段代码是网上大多数人给出的时间戳现实,这个一看便知只能说是取得当前日期,而不能算是时间戳,不用多解释了吧!

1 $now = mktime(0,0,0,date("m"),date("d"),date("Y"));
2 echo "now is ".date("Y/m/d", $now);

显示结果:

now is 2012/05/30

显然这不是我想要的结果。

于是,按照旧有的思维,我想当然的改造成下面这个形式:

1 $now = mktime(date("h"),date("M"),date("s"),date("m"),date("d"),date("Y"));
2 echo "now is ".date("Y/M/d h:i:s", $now);

注意红色的部分,通常如果月份用m,那么分钟就应该是M。或者前者用M,后者用m。

显示结果:
Warning: mktime() expects parameter 2 to be long, string given in D:\usr\webroot\testPHP\index.php on line 46
now is 1970/01/01 08:Jan:00

看来主观臆断是不可取的,PHP的语法和其他的语言还是有些区别的。

不卖关子了,还是直接给大家正确的答案

1 $now = mktime(date("h"),date("i"),date("s"),date("m"),date("d"),date("Y"));
2 echo "now is ".date("Y/m/d h:i:s", $now);

哈哈~是“i”而不是什么m或者M,这里给出大家这个示例只是想让PHP的初学少走一些弯路。

至于M是什么意思,大家自己做一下就明白了...嘿嘿!!!

显示结果:

now is 2012/05/30 04:54:25

网络上互相复制文章的人太多,没有多少人去深究这个,让如我一样的PHP初学者无所适从。大家拷贝复制之前是不是多动动手自己实现一下在写出了,对自己是个提高,对读者也是一直负责的态度。