Home > Article > Backend Development > How to convert a date containing Chinese characters into a timestamp in php
Method: First use the date_parse_from_format() function to return an associative array containing Chinese date information according to the specified format, the syntax is "date_parse_from_format('Y year m month d day', $str)"; then use the mktime() function Convert it to timestamp.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php Chinese date to timestamp
<?php header('content-type:text/html;charset=utf-8'); $str = '2021年03月31号'; $arr = date_parse_from_format('Y年m月d日',$str); $time = mktime(0,0,0,$arr['month'],$arr['day'],$arr['year']); var_dump($arr); echo '2021年03月31号对应时间戳为:'.$time; ?>
Output:
Related function description:
##date_parse_from_format( ) The function returns an associative array containing the specified date information according to the specified format.
date_parse_from_format(format,date);
Description | |
---|---|
format | Required. Specifies the format (formats accepted by date_create_from_format()).|
date | Required. Specify date as a string value.
mktime() The function returns the UNIX timestamp of a date.
Syntaxmktime(hour,minute,second,month,day,year,is_dst);
Description | |
---|---|
hour | Optional. Specified hours.|
minute | Optional. prescribed points.|
second | Optional. Specifies seconds.|
month | Optional. Specified month.|
day | Optional. Specify days.|
year##Optional. Specified year. | |
Optional. Set to 1 if the time is during daylight saving time, 0 otherwise, or -1 (default) if unknown. If unknown, PHP will try to find it itself (possibly producing unexpected results). | Note:This parameter is deprecated in PHP 5.1.0. Instead, new time zone handling features are used. |
The above is the detailed content of How to convert a date containing Chinese characters into a timestamp in php. For more information, please follow other related articles on the PHP Chinese website!