Home >Backend Development >PHP Problem >How to convert Chinese date string to time format in php
php method to convert Chinese date string to time format: 1. Create a php sample file; 2. Define a Chinese date string; 3. Implement it through the "date_parse_from_format()" and "mktime()" functions Just convert the date format.
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer
How to convert Chinese date string to time format in php?
php processes the date containing Chinese year, month and day and converts it to a timestamp (for example, November 08, 2017 to a timestamp)
<?php $str = '2017年11月08号'; $arr = date_parse_from_format('Y年m月d日',$str); $time = mktime(0,0,0,$arr['month'],$arr['day'],$arr['year']); print_r($arr); echo '2017年11月08号对应时间戳为:'.$time; ?>
The result is
Array( [year] => 2017 [month] => 11 [day] => 8 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => )
2017 The corresponding timestamp for November 8th is: 1510070400
date_parse_from_format() function returns an associative array containing the specified date information according to the specified format.
date_parse_from_format(format,date);
mktime(hour,minute,second,month,day,year,is_dst);year is optional. Specified year.
<?php echo(date("M-d-Y",mktime(0,0,0,12,36,2001))); echo(date("M-d-Y",mktime(0,0,0,14,1,2001))); echo(date("M-d-Y",mktime(0,0,0,1,1,2001))); echo(date("M-d-Y",mktime(0,0,0,1,1,99))); ?>Output
Jan-05-2002 Feb-01-2002 Jan-01-2001 Jan-01-1999
PHP Video Tutorial"
The above is the detailed content of How to convert Chinese date string to time format in php. For more information, please follow other related articles on the PHP Chinese website!