strtotime()
时间: 2023-11-14 21:05:49 浏览: 33
strtotime() is a PHP function used to convert a human-readable date or time string into a Unix timestamp. It takes a string as an argument and returns the number of seconds since January 1 1970 00:00:00 UTC.
Some examples of strtotime() input formats include:
- "now"
- "tomorrow"
- "next Monday"
- "last day of February 2021"
- "2021-12-31 23:59:59"
Note that strtotime() has some limitations and may not work for all date/time formats. It also assumes that the input date/time is in the server's timezone. To convert to a different timezone, you can use the DateTime class instead.
相关问题
php strtotime
`strtotime()` 函数是一个用于将人类可读的日期时间格式转换为 Unix 时间戳的 PHP 函数。它接受一个表示日期时间的字符串作为参数,并返回该日期时间的 Unix 时间戳。
例如,你可以使用 `strtotime()` 函数将一个日期字符串转换为 Unix 时间戳,如下所示:
```php
$dateString = "2022-01-01 00:00:00";
$timestamp = strtotime($dateString);
echo $timestamp; // 输出:1640995200
```
在上面的例子中,`strtotime()` 函数将字符串 "2022-01-01 00:00:00" 转换为 Unix 时间戳,表示该日期时间距离 1970 年 1 月 1 日 00:00:00 的秒数。
需要注意的是,`strtotime()` 函数对于不同的日期时间格式有一些约束和限制,并且会根据当前时区进行日期时间转换。详细的用法和支持的日期时间格式,请参考 PHP 官方文档中 `strtotime()` 函数的说明。
PHP strtotime
PHP中的strtotime函数可以将人类可读的日期时间字符串转换为UNIX时间戳。它的语法如下:
```
strtotime ( string $time [, int $now = time() ] ) : int|false
```
其中 $time 参数是需要转换的日期时间字符串,$now 参数是可选的,默认值为当前时间的UNIX时间戳。函数会返回转换后的UNIX时间戳,如果转换失败则返回false。
例如,以下代码可以将字符串"2022-01-01 00:00:00"转换为UNIX时间戳:
```php
$timestamp = strtotime("2022-01-01 00:00:00");
echo $timestamp;
```
输出结果为:
```
1640995200
```
这个时间戳表示的是2022年1月1日0时0分0秒距离UNIX纪元(1970年1月1日0时0分0秒)的秒数。