strtotime php,php strtotime函数怎么用
PHP strtotime()函数用于接受表示日期时间的字符串参数,将任何英文文本的日期或时间描述解析为Unix时间戳,语法为“strtotime (time,now)”,若成功则返回时间戳,失败则返回FALSE。
PHP strtotime()函数怎么用?
strtotime()函数是PHP中的一个内置函数。
strtotime()函数接受表示日期时间的字符串参数,将任何英文文本的日期或时间描述解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数);例如,“now”指的是当前日期。该函数返回自Unix Epoch以来的秒数。我们还可以使用date()函数以日期格式返回英文文本日期时间。
基本语法:strtotime(time,now);
参数:strtotime()函数接受两个参数
● time:指定英文文本时间或日期描述,表示要返回的日期或时间。该函数解析字符串并以秒为单位返回时间;不可省略。
● now:规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。
注:由于时间/日期不是静态的,因此输出会有所不同。
下面通过代码示例来看看PHP strtotime()函数的使用
示例1:显示当前时间<?php
header("content-type:text/html;charset=utf-8");
//以秒为单位显示当前时间
echo "以秒为单位显示当前时间:".strtotime("now"), "
";
// 以日期格式显示当前时间
echo "以日期格式显示当前时间:".date("Y-m-d", strtotime("now"))."\n";
?>
输出:以秒为单位显示当前时间:1556162013
以日期格式显示当前时间:2019-04-25
示例2:显示“12th february 2017”所描述的时间日期<?php
header("content-type:text/html;charset=utf-8");
// 以秒为单位显示转换后的日期时间
echo "以秒为单位显示:".strtotime("12th february 2017")."
";
// 以日期格式显示转换后的日期时间
echo "以日期格式显示:".date("Y-m-d", strtotime("12th february 2017"))."
";
?>
输出:以秒为单位显示:1486854000
以日期格式显示:2017-02-12
示例3:显示当前时间的下周日的日期<?php
header("content-type:text/html;charset=utf-8");
// 以秒为单位显示转换后的日期时间
echo "以秒为单位显示:".strtotime("next sunday")."
";
// 以日期格式显示转换后的日期时间
echo "以日期格式显示:".date("Y-m-d", strtotime("next sunday"))."
";
?>
输出:以秒为单位显示:1556402400
以日期格式显示:2019-04-28
相关视频教程推荐:《PHP教程》
以上就是本篇文章的全部内容,希望能对大家的学习有所帮助。更多精彩内容大家可以关注php中文网相关教程栏目!!!
strtotime php,php strtotime函数怎么用相关推荐
- php设置pst时区,php设置时区和strtotime转化为时间戳函数
date_default_timezone_set('PRC');//设置中华人民共和国标准时间 strtotime - 将任何英文文本的日期时间描述解析为 Unix 时间戳 格式:int strto ...
- php strtotime月底,php strtotime 大小月问题
最近做账单这块,经常会碰到strtotime结合-1 month, +1 month, next month的问题, 然后就会觉得这个函数有点不那么靠谱, 因为大小月的原因,动不动就出问题. 用的时候 ...
- php strtotime,php的strtotime举例
1.上周日午夜 strtotime("last sunday"); 2.本周日午夜 strtotime("this sunday"); 3.今天午夜 strto ...
- php strtotime,php中strtotime什么意思
strtotime PHP内置时间函数 (PHP 4, PHP 5) strtotime()可以用英语的自然语言创建某个时刻的时间戳 函数语法:int strtotime(string $time[, ...
- strtotime('yesterday')与strtotime('-1 day')获取的时间戳
echo date('Y-m-d H:i:s',strtotime('yesterday')); echo '<br />'; echo date('Y-m-d H:i:s',strtot ...
- php中strtotime的意思,php中strtotime函数用法详解
本文实例讲述了php中strtotime函数用法.分享给大家供大家参考.具体如下: strtotime(字符串$时间[,诠释$现在])int strtotime(string $time [,int ...
- PHP中strtotime函数有范围吗,PHP中使用strtotime函数注意事项
strtotime函数在是大家常用的一个时间日期转换成单位S的一个函数了,但是这个函数有一个细节大家可能没有注意到,就是 使用的时候需要考虑 有31天和 2月份的情况,所以,如果没有考虑这个特殊的情况 ...
- 用strtotime()和date()函数算出2019年9月的周日日期
strtotime---用于接收两个参数,第一个参数是格式化的日期数据如:date('Y-m-d'),第二个参数有如'+7 day' 函数版 <?php $firstsunday = strto ...
- PHP日期时间函数之strtotime()
定义和用法 strtotime() strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳. 语法 strtotime(time,now) 参数 描述 time 规定要解析的 ...
最新文章
- Python 生成 JWT(json web token) 及 解析方式
- IOS开发学习笔记018- 一般控件的使用
- linux下文件权限管理
- c++学习笔记之基础篇
- 【Java】区分BigDecimal的toString()和toPlainString()
- 性能,不是不重要,而是,它没有可维护性重要
- 中国AI专利申请数超美国近2.5倍
- three.js特效
- UCHome二次开发 模板基础语法
- 哔哩下载姬(B站下载工具)
- Weiss-(DSAA - in C,1.3)字谜游戏
- linux中进程unit是什么意思,linux-日常运维- unit介绍
- 大数据—数据收集系统介绍(Flume,Sqoop)
- IGRP原理及配置案例
- Java时间操作类库—Joda-Time
- pqmagic 8.0中文版—硬盘分区魔术师
- RGB565颜色表,附RGB888转RGB565工具,RGB24转RGB565工具
- 常用经方的应用体会
- 云服务器(ubuntu)搭建nginx-rtmp服务器 实现直播功能(纯命令行操作)
- IntelliJ IDEA 注册码(phpstorm等IDE)
热门文章
- 电商主题BANNER传统促销喜庆红色节日海报,C4D打造时尚场景
- 高品质美食PSD分层海报,吸睛有食欲
- 早秋精品电商男装页面\海报设计PSD模板
- 可临摹学习的精致的音乐播放器界面设计ui模板
- Python给指定文件打上数字签名
- Linux网络协议栈:Linux 中每个 TCP 连接最少占用多少内存?
- abrtd:Executable ‘some execution‘ doesn‘t belong to any package and ProcessUnpackaged is set to ‘no‘
- 【转】内核通信之 Netlink 源码分析和实例分析
- 高性能网关设备及服务实践
- 论肱二头肌在日常生活中的锻炼的持久战|健身达人