现在的位置: 首页 > 综合 > 正文

php strtotime()

2014年01月27日 ⁄ 综合 ⁄ 共 1271字 ⁄ 字号 评论关闭

1.strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。

2.int
strtotime ( string $time [, int $now ] )


3.

参数 

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”等等。

4.相关和顺序说明: 

+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

抱歉!评论已关闭.