strtotime() 函数

本文详细介绍了PHP中的strtotime()函数,该函数可以将英文文本的日期时间描述解析为Unix时间戳。文章提供了函数的定义、语法、参数说明及使用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2007年11月12日 星期一 10:46

Definition and Usage
定义和用法

The strtotime() function parses an English textual date or time into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).
strtotime()函数的作用是:将任何英文文本的日期时间描述解析为Unix时间戳(从1970年1月1日(GMT)起经过的秒数)。

Syntax
语法

strtotime(time,now)

Parameter参数Description描述
timeRequired. Specifies the time string to parse
必要参数。指定需要被解析的时间字符串。
nowOptional. Specifies the timestamp used to calculate the returned value. If this parameter is omitted, current time is used
可选参数。指定用来计算返回值的时间戳。如果这个参数被忽略,那么将默认使用当前时间


Tips and Notes
注意点

Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
注意:如果时间是以两位数字的格式指定的,那么数字“0-69”指的是2000-2069年,数字“70-100”指的是1970-2000年。

Note: In PHP 5.1.0 this function returns false on failure (earlier versions returns -1).
注意:在 PHP 5.1.0版本中,如果函数失效,它将返回false(早期版本将返回 -1)。


Example
案例

<?php
echo(strtotime("now") . "<br />");
echo(strtotime("3 October 2005") . "<br />");
echo(strtotime("+5 hours") . "<br />");
echo(strtotime("+1 week") . "<br />");
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br />");
echo(strtotime("next Monday") . "<br />");
echo(strtotime("last Sunday"));
?>

The output of the code above could be:
上述代码将输出下面的结果:

1138614504
1128290400
1138632504
1139219304
1139503709
1139180400
1138489200
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值