php 时间函数
2015-10-18 21:19
651 查看
时间戳
<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$timestamp</span>=time();<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>拿到当前的时间戳</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
设置时区
<code class="hljs scss has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-function" style="box-sizing: border-box;">date_default_timezone_get()</span>;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//得到当前时区</span> <span class="hljs-function" style="box-sizing: border-box;">date_default_timezone_set(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'PRC'</span>)</span>;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//设置默认时区为中国</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
格式化时间戳
<code class="hljs mel has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">echo <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">date</span>(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'Y年m日d天 H:i:s'</span>); <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//date返回格式化的当前时间</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$date3</span>=<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">date</span>(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'Y-m-d H:i:s'</span>,<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"1228348800"</span>);</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
拿到某个时间的时间戳
<code class="hljs scss has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-function" style="box-sizing: border-box;">mktime(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2014</span>)</span>;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//返回2014年9月10号的时间戳</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
测试代码执行时间
<code class="hljs r has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$start_time=microtime(); //<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">...</span>执行的代码 $end_time=microtime(); $execute_time=$end_time-$start_time;</code>
相关文章推荐
- How to install php evn on ubuntu
- vsftpd配置文件详解
- zend framework virtualhost设置方法
- php环境扩展包so
- phpStorm生成php文件不是utf-8格式
- 计算php程序的执行时间
- PHP实现归并排序(合并排序)--算法原理分析
- wamp无法登录phpmyadmin问题
- php项目琐碎总结
- MyViewPagerAdpter 和 MyFragmentPagerAdapter
- php 中常用字符串
- PHP中array_chunk的用法
- 在windows上安装php扩展
- PHP PDO prepare()、execute()和bindParam()方法详解
- yii学习笔记 - model
- php定时运行任务(windows7)
- yii笔记—利用页面表单实现数据的添加
- PHP Yii gii自动生成的模块代码无法执行,报错:Internal Server Error include(Controller.php)
- Smarty标签变量来源
- Smarty运用,赋值数组,定界符冲突