php获取当前时间和转换格式
2016-10-26 11:12
253 查看
## 获取时间和转换格式
```
//1.time():返回当前时间的Unix时间戳
$stimestamp = time();
$date = date("Y-m-d h:i:sa",$stimestamp)
//2.mktime():返回一个指定日期的Unix时间戳
//语法:mktime(hour,minute,second,month,day,year,is_dst);
$stimestamp = mktime(9,12,31,6,10,2016)
$date = date("Y-m-d h:i:sa",$stimestamp)
//3.date(formate,timestamp);返回时间戳对应的日期
$date = date("Y-m-d h:i:sa",$stimestamp)
//4.strtotime();函数将任何英文文本的日期或时间描述解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数)。
//语法:strtotime(time,now);
strtotime('2014-09-10 11:01:46');
echo(strtotime("now") . "<br>");
echo(strtotime("15 October 1980") . "<br>");
echo(strtotime("+5 hours") . "<br>");
echo(strtotime("+1 week") . "<br>");
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>");
echo(strtotime("next Monday") . "<br>");
echo(strtotime("last Sunday"));
```
```
//1.time():返回当前时间的Unix时间戳
$stimestamp = time();
$date = date("Y-m-d h:i:sa",$stimestamp)
//2.mktime():返回一个指定日期的Unix时间戳
//语法:mktime(hour,minute,second,month,day,year,is_dst);
$stimestamp = mktime(9,12,31,6,10,2016)
$date = date("Y-m-d h:i:sa",$stimestamp)
//3.date(formate,timestamp);返回时间戳对应的日期
$date = date("Y-m-d h:i:sa",$stimestamp)
//4.strtotime();函数将任何英文文本的日期或时间描述解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数)。
//语法:strtotime(time,now);
strtotime('2014-09-10 11:01:46');
echo(strtotime("now") . "<br>");
echo(strtotime("15 October 1980") . "<br>");
echo(strtotime("+5 hours") . "<br>");
echo(strtotime("+1 week") . "<br>");
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>");
echo(strtotime("next Monday") . "<br>");
echo(strtotime("last Sunday"));
```
相关文章推荐
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- 【转】PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- java/python中获取当前系统时间,并与字符串相互转换格式,或者转化成秒数,天数等整数
- PHP获取当前时间、时间戳的各种格式写法汇总
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- C++如何获取当前时间并转换成相应的格式字符串
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- PHP获取当前时间、时间戳的各种格式写法汇总
- php获取当前日期时间 & php日期转时间戳,指定日期转换成时间戳
- C++如何获取当前时间并转换成相应的格式字符串.
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- js 获取当前时间格式怎么转换?
- 秒转换成日期/秒转换成时间格式获取当前时间,日期
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- 在C++中获取当前时间并转换为可读时间格式(Win32和Linux通用)
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- Js获取当前日期时间、比较及正则表达式转换格式