热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

PHPstrtotime深入理解应用实例

PHPstrtotime函数将任何英文文本的日期时间描述解析为Unix时间戳[将系统时间转化成unix时间戳],下面是strtotime有

PHP strtotime函数将任何英文文本的日期时间描述解析为Unix时间戳[将系统时间转化成unix时间戳],下面是strtotime有关参数说明:

语法

strtotime(time,now)
参数 描述
time 规定要解析的时间字符串。
now 用来计算返回值的时间戳。如果省略该参数,则使用当前时间。


下面是后一种方式的可使用参数清单,其中“当前时间”是指strtotime第二个参数now的值,默认为当前时间
1.月,日英文名及其常用缩写清单:
january,february,march,april,may,june,july,august,september,sept,october,november,december,
sunday,monday,tuesday,tues,wednesday,wednes,thursday,thur,thurs,friday,saturday

2.时间参数和祥细描述:
am : the time is before noon 上午
pm : the time is noon or later 下午
year: one year; for example, “next year” 年,比如“next year”代表明年
month : one month; for example, “last month” 月,比如“last month”代表上一月
fortnight : two weeks; for example, “a fortnight ago” 两周,比如“a fortnight ago”代表两周前
week : one week 周
day: a day 天
hour: an hour 小时
minute : a minute 分钟
min : same as minute 同“minute”
second : a second 秒
sec : same as second 同“second”

3.相关和顺序说明:
+n/-n :以当前时间算,加个减指定的时间,比如”+1 hour”是指当前时间加一小时
ago :time relative to now; such as “24 hours ago”  以当前时间往前算,比如”24 hours ago”代表“24小时前”
tomorrow : 24 hours later than the current date and time 以当前时间(包括日期和时间)为标准,明天同一时间
yesterday : 24 hours earlier than the current date and time 以当前时间(包括日期和时间)为标准,昨天同一时间
today : the current date and time 当前时间(包括日期和时间)
now : the current date and time 当前时间(包括日期和时间)
last : modifier meaning “the preceding”; for example, “last tuesday” 代表“上一个”,比如“last tuesday”代表“上周二同一时间”
this : the given time during the current day or the next occurrence of the given time; for example, “this 7am” gives the timestamp for 07:00 on the current day, while “this week” gives the timestamp for one week from the current time 当天的指定时间或下面一个时间段的时间戳,比如“this 7am”给出当天7:00的时间戳,而“this week”给出的是从当前时间开始的一整周的时间戳,也就是当前时间(经本人测试:strtotime('this week')=strtotime('now'));
next : modifier meaning the current time value of the subject plus one; for example, “next hour” 当前时间加上指定的时间,比如“next hour”是指当前时间加上一小时,即加3600

//先到这,下面的还没时间翻译
first : ordinal modifier, esp. for months; for example, “May first” (actually, it's just the same as next)
third : see first (note that there is no “second” for ordinality, since that would conflict with the second time value)
fourth : see first
fifth : see first
sixth : see first
seventh : see first
eighth : see first
ninth : see first
tenth : see first
eleventh : see first
twelfth : see first

4.时区描述:
gmt : Greenwich Mean Time
ut : Coordinated Universal Time
utc : same as ut
wet : Western European Time
bst : British Summer Time
wat : West Africa Time
at : Azores Time
ast : Atlantic Standard Time
adt : Atlantic Daylight Time
est : Eastern Standard Time
edt : Eastern Daylight Time
cst : Central Standard Time
cdt : Central Daylight Time
mst : Mountain Standard Time
mdt : Mountain Daylight Time
pst : Pacific Standard Time
pdt : Pacific Daylight Time
yst : Yukon Standard Time
ydt : Yukon Daylight Time
hst : Hawaii Standard Time
hdt : Hawaii Daylight Time
cat : Central Alaska Time
akst : Alaska Standard Time
akdt : Alaska Daylight Time
ahst : Alaska-Hawaii Standard Time
nt : Nome Time
idlw : International Date Line West
cet : Central European Time
met : Middle European Time
mewt : Middle European Winter Time
mest : Middle European Summer Time
mesz : Middle European Summer Time
swt : Swedish Winter Time
sst : Swedish Summer Time
fwt : French Winter Time
fst : French Summer Time
eet : Eastern Europe Time, USSR Zone 1
bt : Baghdad Time, USSR Zone 2
zp4 : USSR Zone 3
zp5 : USSR Zone 4
zp6 : USSR Zone 5
wast : West Australian Standard Time
wadt : West Australian Daylight Time
cct : China Coast Time, USSR Zone 7
jst : Japan Standard Time, USSR Zone 8
east : Eastern Australian Standard Time
eadt : Eastern Australian Daylight Time
gst : Guam Standard Time, USSR Zone 9
nzt : New Zealand Time
nzst : New Zealand Standard Time
nzdt : New Zealand Daylight Time
idle : International Date Line East
 

操作实例

一,获取指定日期的unix时间戳 strtotime(”2009-1-22″) 示例如下:

echo strtotime(”2009-1-22“) 结果:1232553600
说明:返回2009年1月22日0点0分0秒时间戳

二,获取英文文本日期时间 示例如下:

便于比较,使用date将当时间戳与指定时间戳转换成系统时间

(1)打印明天此时的时间戳strtotime(”+1 day“)
当前时间:echo date(”Y-m-d H:i:s”,time()) 结果:2009-01-22 09:40:25
指定时间:echo date(”Y-m-d H:i:s”,strtotime(”+1 day”)) 结果:2009-01-23 09:40:25

(2)打印昨天此时的时间戳strtotime(”-1 day“)
当前时间:echo date(”Y-m-d H:i:s”,time()) 结果:2009-01-22 09:40:25
指定时间:echo date(”Y-m-d H:i:s”,strtotime(”-1 day”)) 结果:2009-01-21 09:40:25

(3)打印下个星期此时的时间戳strtotime(”+1 week“)
当前时间:echo date(”Y-m-d H:i:s”,time()) 结果:2009-01-22 09:40:25
指定时间:echo date(”Y-m-d H:i:s”,strtotime(”+1 week”)) 结果:2009-01-29 09:40:25

(4)打印上个星期此时的时间戳strtotime(”-1 week“)
当前时间:echo date(”Y-m-d H:i:s”,time()) 结果:2009-01-22 09:40:25
指定时间:echo date(”Y-m-d H:i:s”,strtotime(”-1 week”)) 结果:2009-01-15 09:40:25

(5)打印指定下星期几的时

推荐阅读
  • 一、Hadoop来历Hadoop的思想来源于Google在做搜索引擎的时候出现一个很大的问题就是这么多网页我如何才能以最快的速度来搜索到,由于这个问题Google发明 ... [详细]
  • 学习SLAM的女生,很酷
    本文介绍了学习SLAM的女生的故事,她们选择SLAM作为研究方向,面临各种学习挑战,但坚持不懈,最终获得成功。文章鼓励未来想走科研道路的女生勇敢追求自己的梦想,同时提到了一位正在英国攻读硕士学位的女生与SLAM结缘的经历。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了brain的意思、读音、翻译、用法、发音、词组、同反义词等内容,以及脑新东方在线英语词典的相关信息。还包括了brain的词汇搭配、形容词和名词的用法,以及与brain相关的短语和词组。此外,还介绍了与brain相关的医学术语和智囊团等相关内容。 ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • Echarts图表重复加载、axis重复多次请求问题解决记录
    文章目录1.需求描述2.问题描述正常状态:问题状态:3.解决方法1.需求描述使用Echats实现了一个中国地图:通过选择查询周期&#x ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • Python字典推导式及循环列表生成字典方法
    本文介绍了Python中使用字典推导式和循环列表生成字典的方法,包括通过循环列表生成相应的字典,并给出了执行结果。详细讲解了代码实现过程。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • “你永远都不知道明天和‘公司的意外’哪个先来。”疫情期间,这是我们最战战兢兢的心情。但是显然,有些人体会不了。这份行业数据,让笔者“柠檬” ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
author-avatar
伤心怪人_234
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有