位置: 编程技术 - 正文

PHP:strtotime()的用法_Date Time函数(php strftime)

编辑:rootadmin
strtotime

推荐整理分享PHP:strtotime()的用法_Date Time函数(php strftime),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:php中strtotime,php time,php strftime,php time,php strftime,php set time limit,php strftime,php timestamp,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 4, PHP 5)

strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳

说明 int strtotime ( string $time [, int $now = time() ] )

本函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 :: GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数则用系统当前时间。

本函数将使用 TZ 环境变量(如果有的话)来计算时间戳。自 PHP 5.1.0 起有更容易的方法来定义时区用于所有的日期/时间函数。此过程在 date_default_timezone_get() 函数页面中有说明。

参数

time

日期/时间字符串。正确格式的说明详见 日期与时间格式。

now

用来计算返回值的时间戳。

返回值

成功则返回时间戳,否则返回 FALSE。在 PHP 5.1.0 之前本函数在失败时返回 -1。

错误/异常

在每 次调用日期/时间函数时,如果时区无效则会引发 E_NOTICE 错误,如果使用系统设定值或 TZ环境变量,则会引发 E_STRICT 或 E_WARNING 消息。参见date_default_timezone_set()。

更新日志

版本 说明 5.3.0 在 PHP 5.3.0 之前, : 不是一个有效的格式,并且 strtotime() 会返回 FALSE。 5.2.7 In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a month where that weekday was the first day of the month would incorrectly add one week to the returned timestamp. This has been corrected in 5.2.7 and later versions. 5.1.0 失败时返回 FALSE,不再是 -1。 5.1.0

现在发布 E_STRICT 和 E_NOTICE时区错误。

5.0.2 在 PHP 5 中到 5.0.2 之前,"now" 和其它相对时间从今天午夜起错误计算了。这和正确从当前时间起计算的其它版本不同。 5.0.0 Microseconds began to be allowed, but they are ignored. 4.4.0 在 PHP 4.4 之前,"next" 被错误计算为 +2。对此通常的解决方法是用 "+1"。

范例

PHP:strtotime()的用法_Date Time函数(php strftime)

Example #1 strtotime() 例子

<?phpechostrtotime("now"),"n";echostrtotime("September"),"n";echostrtotime("+1day"),"n";echostrtotime("+1week"),"n";echostrtotime("+1week2days4hours2seconds"),"n";echostrtotime("nextThursday"),"n";echostrtotime("lastMonday"),"n";?>

Example #2 失败检查

<?php$str='NotGood';//previoustoPHP5.1.0youwouldcomparewith-1,insteadoffalseif(($timestamp=strtotime($str))===false){echo"Thestring($str)isbogus";}else{echo"$str==".date('ldSofFYh:i:sA',$timestamp);}?>

注释

Note:

如果给定的年份是两位数字的格式,则其值 0- 表示 -,- 表示 -。 See the notes below for possible differences on bit systems (possible dates might end on -- ::).

Note:

有效的时间戳通常从 Fri, Dec :: GMT 到 Tue, Jan :: GMT(对应于 位有符号整数的最小值和最大值)。不是所有的平台都支持负的时间戳,那么日记范围就被限制为不能早于 Unix 纪元。这意味着在 年 1 月 1 日之前的日期将不能用在 Windows,一些 Linux 版本,以及几个其它的操作系统中。不过 PHP 5.1.0 及更新的版本克服了此限制。

For -bit versions of PHP, the valid range of a timestamp is effectively infinite, as bits can represent approximately billion years in either direction.

Note:

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

To avoid potential ambiguity, it&#;s best to use ISO (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.

Note:

Using this function for mathematical operations is not advisable. It is better to use DateTime::add() and DateTime::sub() in PHP 5.3 and later, or DateTime::modify() in PHP 5.2.

参见

Date and Time Formats DateTime::createFromFormat() - Returns new DateTime object formatted according to the specified format checkdate() - 验证一个格里高里日期 strptime() - 解析由 strftime 生成的日期/时间

PHP:time()的用法_Date Time函数 time(PHP4,PHP5)time返回当前的Unix时间戳说明inttime(void)返回自从Unix纪元(格林威治时间年1月1日::)到当前时间的秒数。范例Example#1time()例子?php$nextWe

PHP:strftime()的用法_Date Time函数 strftime(PHP4,PHP5)strftime根据区域设置格式化本地时间/日期说明stringstrftime(string$format[,int$timestamp=time()])返回用给定的格式字串对给出的timestamp进行格式输

PHP:strptime()的用法_Date Time函数 strptime(PHP5=5.1.0)strptime解析由strftime()生成的日期/时间说明arraystrptime(string$date,string$format)strptime()返回一个将date解析后的数组,如果出错返回FALSE。月份

标签: php strftime

本文链接地址:https://www.jiuchutong.com/biancheng/287356.html 转载请保留说明!

上一篇:PHP:chroot()的用法_Directory函数(php floor())

下一篇:PHP:time()的用法_Date Time函数(php timeout)

  • 小规模纳税人能开1%的专票吗
  • 转登记纳税人按规定再次登记为一般纳税人后
  • 固定资产的入账
  • 银行提供资金
  • 银行端查询缴税凭证怎么盖章
  • 国际货物运输07113
  • 慰问金计入什么明细科目
  • 归集研发费用时怎么计算
  • 退休返聘人员购买什么商业保险
  • 增值税专用发票电子版
  • 小规模纳税人的认定标准是什么
  • 分公司开票总公司收款行吗
  • 个人缴纳失业保险的比例
  • 代扣代缴增值税纳税义务发生时间
  • 个体工商户转为个人独资企业
  • 怎么查询发票记录
  • 文化事业费征收
  • 滴滴发票报销是什么意思
  • 增值税发票系统升级版
  • 本期填写的适用3减1政策的本期发生额大于
  • 暂估材料太多怎么办
  • 收取违约金如何入账
  • 电信网络网速变快设置
  • 股东借钱给公司怎么写借条
  • 绝地求生闪退怎么解决win10
  • nuxt支持vue3吗
  • 对违规送礼行为怎么处理
  • 电脑麦克风对方听不到声音怎么办
  • win11系统设置快捷键
  • 企业清算剩余财产分配是否交个人所得税
  • PHP:realpath_cache_get()的用法_Filesystem函数
  • 补缴以前年度公积金误入当年费怎么办
  • framework core
  • 股东出资未注明投资款可以通过验资报告处理么
  • 微信小程序登录后端
  • 机关单位工会经费提取比例
  • yii gridview
  • 更换电脑金税盘的数据如何导入新电脑
  • 如何进行iframe框架切换
  • php增删改查mysqli实例
  • 劳务费怎么做会计分裤
  • 代扣代缴境外增值税税率是多少
  • 多缴纳的社保怎么查询
  • 高新企业奖励要交企业所得税吗
  • 销售费用工资是什么科目
  • 盈余公积一定要计提吗
  • mysql "too many connections" 错误 之 mysql解决方法
  • 销售自己使用过的固定资产
  • 哪些合同必须签订书面合同
  • 发票上的印记能去掉吗
  • 同一控制和非同一控制的区别图解
  • 销售货物增值税税率变化
  • 固定资产提前报废当月计提折旧吗
  • 委托代理出口如何缴纳增值税
  • 公司对外投资企业与行政许可的区别是什么
  • 计提增值税如何做账
  • 英飞拓拟2.1亿出售子公司股权
  • 无形资产摊销的会计科目
  • 开立银行承兑汇票利率
  • 职工福利费的扣除标准工资总额包括什么
  • 企业年度财务报告的保管期限为
  • 私人网银可以转账吗
  • 施工企业应收账款周转率多少合适
  • sql-3
  • apt-get update错误
  • 苹果电脑怎么切换系统
  • linux系统磁盘管理的主要内容
  • 在mac下如何安装软件
  • win8怎么把c盘恢复出厂设置
  • mac光盘无法退出怎么解决
  • 2021年win10累积更新
  • windows7禁止开机启动
  • linux系统怎么查看防火墙状态
  • javascript的用法
  • 深入理解python特性pdf百度云
  • androidserviceslibrary停用
  • Python内置的HTTP协议服务器SimpleHTTPServer使用指南
  • 总结网络io模型的特点
  • 单位发的一次性奖励如何扣税
  • 河南省税务局冯伟
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设