php时间函数用法分析,php函数用法
本文实例讲述了php时间函数用法。分享给大家供大家参考,具体如下:
php中有unix时间戳的 相关操作函数,使用很方便
time() 返回当前的 Unix 时间戳
microtime -- 返回当前 Unix 时间戳和微秒数
例 1. 用 microtime() 对脚本的运行计时
<?php /** * Simple function to replicate PHP 5 behaviour */ function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_start = microtime_float(); // Sleep for a while usleep(100); $time_end = microtime_float(); $time = $time_end - $time_start; echo "Did nothing in $time seconds/n"; ?>
mktime()取得一个日期的 Unix 时间戳
int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
参数可以从右向左省略,任何省略的参数会被设置成本地日期和时间的当前值
date()格式化一个本地时间/日期
string date ( string format [, int timestamp] )
提示: 自 PHP 5.1 起在 $_SERVER['REQUEST_TIME'] 中保存了发起该请求时刻的时间戳。
strtotime -- 将任何英文文本的日期时间描述解析为 Unix 时间戳
echo strtotime("+1 day"), "/n"; echo strtotime("+1 week"), "/n";
例2. 某个时间的后一天,后一月
strtotime("+1 day ".$day); strtotime("2008-01-31 +1 month"); strtotime($day." +1 day");
以上形式都正确
PS:本站还提供了一个Unix时间戳转换工具,非常实用,提供给大家参考:
Unix时间戳(timestamp)转换工具:
http://tools.jb51.net/code/unixtime
这里再为大家推荐一款本站的php格式化美化的排版工具,帮助大家在以后的PHP程序设计中进行代码排版:
php代码在线格式化美化工具:
http://tools.jb51.net/code/phpformat
另外,由于php属于C语言风格,因此下面这款工具同样可以实现php代码的格式化:
C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数学运算技巧总结》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《PHP数组(Array)操作技巧大全》、《php排序算法总结》、《PHP常用遍历算法与技巧总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。

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

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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.