strtotime()函数PHP时间格式转化
strtotime()函数:把日期转换成时间戳;
1,strtotime()时间转化
$datetime=strtotime(date());
date("Y-m-d H:i",$datetime)
2,获得今天零点的时间戳
第一步,先获取unix时间戳
$todaytime=strtotime("today")
第二步,再转化成可读日期
使用的时候一定要注意标点符号,英文输入下的双引号
date("Y-m-d H:i:s",$todaytime)
日期格式:"Y-m-d H:i:s" H小时(大写为24小时),i分,s秒
"Y-m-d"只显示年月日;
如:
$todaytime=strtotime("today");
echo '今天开始时间:'.date("Y-m-d H:i:s",$todaytime);
输出结果:
今天开始时间:2021-11-05 00:00:00
获取今天23:59:59
① $nextdaytime=strtotime(date('Y-m-d',time()))+24*60*60-1;
② $nextdaytime=strtotime(date('Y-m-d 23:59:59',time()));
3,常用格式:strtotime()时间转化
获取今天格式
echo strtotime('Today');
echo strtotime(date('Y-m-d'));
获取明天凌晨的时间戳
echo strtotime(date('Y-m-d',strtotime('+1 day')));
其它格式:一看就懂的不再加详细解释:
echo "一周后:".date("Y-m-d",strtotime("+1 week"));
echo "一周零一天一小时一秒后:".date("Y-m-d G:H:s",strtotime("+1 week 1 days 1 hours 1 seconds"));
echo "下个星期一:".date("Y-m-d",strtotime("next Monday"));
echo "上个周一:".date("Y-m-d",strtotime("last Monday"));
echo "一个月前:".date("Y-m-d",strtotime("last month"));
echo "一个月后:".date("Y-m-d",strtotime("+1 month"));
echo "一年后:".date("Y-m-d",strtotime("+1 year"));
在实践中不断的成长,把每一个经历都记录下来,给需要的人一点微薄的帮助,在代码历程上少走弯路。
strtotime()函数PHP时间格式转化相关推荐
- element-UI组件之日期时间选择器与时间格式转化
element-UI组件之日期时间选择器与时间格式转化 日期选择器与时间选择器的一般使用 日期时间选择器 选择日期时间点 选择日期范围 日期选择器 月份范围选择器 禁选日期 用time.getTime ...
- 日期时间格式转化为方便理解的格式
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date;/*** @auth ...
- pandas使用to_datetime函数将时间字符串转化为时间对象、使用dt.tz_localize为转化后的时间对象添加时区信息(timezone)
pandas使用to_datetime函数将时间字符串转化为时间对象.使用dt.tz_localize为转化后的时间对象添加时区信息(timezone) 目录 pandas使用to_datetime函 ...
- C语言标准库里的获取时间函数及时间格式转换详解
C语言标准库里的获取时间函数及时间格式转换详解 头文件: #include <time.h> 相关库函数(截图摘自:https://www.runoob.com/cprogramming/ ...
- js中关于时间格式转化,时间大小比较的方法
一.时间格式的转换 标准时间格式:Mon Aug 08 2022 16:08:28 GMT+0800 (中国标准时间) 时间戳:格林威治时间1970年01月01日00时00分00秒(北京时间1970年 ...
- pandas使用to_datetime函数将时间字符串转化为时间对象、其中月份内容为字母而非数字(例如,“January 2, 2022“)
pandas使用to_datetime函数将时间字符串转化为时间对象.其中月份内容为字母而非数字(例如,"January 2, 2022") 目录 pandas使用to_datet ...
- R语言使用strptime函数把字符串转化为时间对象、使用strftime函数把时间对象转化为字符串实战:指定时区、包含时间、分钟、秒、微妙
R语言使用strptime函数把字符串转化为时间对象.使用strftime函数把时间对象转化为字符串实战:指定时区.包含时间.分钟.秒.微妙 目录
- Linux时间戳和时间格式转化
一.时间戳转化为时间格式 1.场景1:时间戳转化为当前时间格式 命令:date -d @待转化的时间戳 实例:date -d @1556519685 转化结果:Mon Apr 29 14:34:45 ...
- 用to_datetime函数实现时间格式的转化
日常工作中,我们经常需要对Excel表格中的时间格式进行转化,但是各家YYS和YH的格式总是五花八门,用Excel进行转化总是不得心应手,可能是我不太会用吧,所以想到能不能编个python小程序实现不 ...
最新文章
- 漫画:最长公共子序列
- Activity A 启动 Activity B 生命周期
- android 自定义banner,Android项目 引入Banner开源库(轮播图)
- ad13批量安装元件库_ad16如何批量添加封装库?
- Apache ActiveMQ中的消息级别授权
- CUL8R的完整形式是什么?
- 简陋版C语言仿真通讯录之动态内存开辟版本
- 计算机系答辩麻烦,计算机专业的你,答辩时有多卑微?
- 生信人一口气搞定SCI作图与数据处理的技巧,有这一个就妥了!
- 清空网站浏览记录就行啦?看Python如何实时监控网站浏览记录
- MTK 驱动(62)---eMMC RPMB分区介绍
- 第一款Layer 2钱包Rollups Wallet已上线苹果AppStore
- mysql集群集成springboot_springboot配置数据库包括集群下 配置
- ABMultiValueCopyLabelAtIndex使用不当引起的内存泄漏
- muduo源代码分析--Reactor在模型muduo使用(两)
- 计算机系统中引入多道程序设计的目的在于,引入多道程序的目的在于什么
- Word使用中常用的快捷键
- 主流的语音芯片ic方案该如何选 这篇文章可以说清楚
- 计算机链接局域网,window7连接局域网的方法
- Python3之牛吃草问题