搜索
首页后端开发php教程PHP strtotime函数详细介绍

本篇文章介绍了,php中的时间戳函数strtotime()的用法,有需要的朋友,可以参考下。

strtotime函数是一个很好的函数,灵活的运用它,会给你的工作带来不少方便.但PHP的手册中却对此函数的参数没作太多介绍,对些函数的其他介绍也非常少。 先看手册介绍: strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳 格式:int strtotime ( string $time [, int $now ] )   本函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数则用系统当前时间。

  本函数将使用 TZ 环境变量(如果有的话)来计算时间戳。自 PHP 5.1.0 起有更容易的方法来定义时区用于所有的日期/时间函数。此过程在 date_default_timezone_get() 函数页面中有说明。 Note : 如果给定的年份是两位数字的格式,则其值 0-69 表示 2000-2069,70-100 表示 1970-2000。

参数 time 被解析的字符串,格式根据 GNU ? 日期输入格式 的语法。在 PHP 5.0 之前,time 中不允许有毫秒数,自 PHP 5.0 起可以有但是会被忽略掉。 now 用来计算返回值的时间戳。 该参数默认值是当前时间time(),也可以设置为其他时间的时间戳(我一直忽略的一个功能啊,惭愧) 返回值: 成功则返回间戳,否则返回 FALSE 。在 PHP 5.1.0 之前本函数在失败时返回 -1,后面版本返回false.

strtotime的第一个参数可以是我们常见的英文时间格式,比如“2008-8-20”或“10 September 2000 ”等等。也可以是以参数now为基准的时间描述,比如“+1 day”等等。

下面是后一种方式的可使用参数清单,其中“当前时间”是指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

附,具体应用举例。 参见文章:php strtotime()函数用法举例



声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
PHP类型提示如何起作用,包括标量类型,返回类型,联合类型和无效类型?PHP类型提示如何起作用,包括标量类型,返回类型,联合类型和无效类型?Apr 17, 2025 am 12:25 AM

PHP类型提示提升代码质量和可读性。1)标量类型提示:自PHP7.0起,允许在函数参数中指定基本数据类型,如int、float等。2)返回类型提示:确保函数返回值类型的一致性。3)联合类型提示:自PHP8.0起,允许在函数参数或返回值中指定多个类型。4)可空类型提示:允许包含null值,处理可能返回空值的函数。

PHP如何处理对象克隆(克隆关键字)和__clone魔法方法?PHP如何处理对象克隆(克隆关键字)和__clone魔法方法?Apr 17, 2025 am 12:24 AM

PHP中使用clone关键字创建对象副本,并通过\_\_clone魔法方法定制克隆行为。1.使用clone关键字进行浅拷贝,克隆对象的属性但不克隆对象属性内的对象。2.通过\_\_clone方法可以深拷贝嵌套对象,避免浅拷贝问题。3.注意避免克隆中的循环引用和性能问题,优化克隆操作以提高效率。

PHP与Python:用例和应用程序PHP与Python:用例和应用程序Apr 17, 2025 am 12:23 AM

PHP适用于Web开发和内容管理系统,Python适合数据科学、机器学习和自动化脚本。1.PHP在构建快速、可扩展的网站和应用程序方面表现出色,常用于WordPress等CMS。2.Python在数据科学和机器学习领域表现卓越,拥有丰富的库如NumPy和TensorFlow。

描述不同的HTTP缓存标头(例如,Cache-Control,ETAG,最后修饰)。描述不同的HTTP缓存标头(例如,Cache-Control,ETAG,最后修饰)。Apr 17, 2025 am 12:22 AM

HTTP缓存头的关键玩家包括Cache-Control、ETag和Last-Modified。1.Cache-Control用于控制缓存策略,示例:Cache-Control:max-age=3600,public。2.ETag通过唯一标识符验证资源变化,示例:ETag:"686897696a7c876b7e"。3.Last-Modified指示资源最后修改时间,示例:Last-Modified:Wed,21Oct201507:28:00GMT。

说明PHP中的安全密码散列(例如,password_hash,password_verify)。为什么不使用MD5或SHA1?说明PHP中的安全密码散列(例如,password_hash,password_verify)。为什么不使用MD5或SHA1?Apr 17, 2025 am 12:06 AM

在PHP中,应使用password_hash和password_verify函数实现安全的密码哈希处理,不应使用MD5或SHA1。1)password_hash生成包含盐值的哈希,增强安全性。2)password_verify验证密码,通过比较哈希值确保安全。3)MD5和SHA1易受攻击且缺乏盐值,不适合现代密码安全。

PHP:服务器端脚本语言的简介PHP:服务器端脚本语言的简介Apr 16, 2025 am 12:18 AM

PHP是一种服务器端脚本语言,用于动态网页开发和服务器端应用程序。1.PHP是一种解释型语言,无需编译,适合快速开发。2.PHP代码嵌入HTML中,易于网页开发。3.PHP处理服务器端逻辑,生成HTML输出,支持用户交互和数据处理。4.PHP可与数据库交互,处理表单提交,执行服务器端任务。

PHP和网络:探索其长期影响PHP和网络:探索其长期影响Apr 16, 2025 am 12:17 AM

PHP在过去几十年中塑造了网络,并将继续在Web开发中扮演重要角色。1)PHP起源于1994年,因其易用性和与MySQL的无缝集成成为开发者首选。2)其核心功能包括生成动态内容和与数据库的集成,使得网站能够实时更新和个性化展示。3)PHP的广泛应用和生态系统推动了其长期影响,但也面临版本更新和安全性挑战。4)近年来的性能改进,如PHP7的发布,使其能与现代语言竞争。5)未来,PHP需应对容器化、微服务等新挑战,但其灵活性和活跃社区使其具备适应能力。

为什么要使用PHP?解释的优点和好处为什么要使用PHP?解释的优点和好处Apr 16, 2025 am 12:16 AM

PHP的核心优势包括易于学习、强大的web开发支持、丰富的库和框架、高性能和可扩展性、跨平台兼容性以及成本效益高。1)易于学习和使用,适合初学者;2)与web服务器集成好,支持多种数据库;3)拥有如Laravel等强大框架;4)通过优化可实现高性能;5)支持多种操作系统;6)开源,降低开发成本。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前By尊渡假赌尊渡假赌尊渡假赌

热工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境