Home  >  Article  >  Backend Development  >  How to convert a date containing Chinese characters into a timestamp in php

How to convert a date containing Chinese characters into a timestamp in php

青灯夜游
青灯夜游Original
2021-03-31 19:02:552358browse

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.

How to convert a date containing Chinese characters into a timestamp in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php Chinese date to timestamp

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
$str = &#39;2021年03月31号&#39;;
$arr = date_parse_from_format(&#39;Y年m月d日&#39;,$str);
$time = mktime(0,0,0,$arr[&#39;month&#39;],$arr[&#39;day&#39;],$arr[&#39;year&#39;]);
var_dump($arr);
echo &#39;2021年03月31号对应时间戳为:&#39;.$time;
?>

Output:

How to convert a date containing Chinese characters into a timestamp in php

Related function description:

##date_parse_from_format( ) The function returns an associative array containing the specified date information according to the specified format.

Syntax

date_parse_from_format(format,date);

ParametersDescriptionRequired. Specifies the format (formats accepted by date_create_from_format()). Required. Specify date as a string value.
format
date

mktime() The function returns the UNIX timestamp of a date.

Syntax

mktime(hour,minute,second,month,day,year,is_dst);

ParametersDescriptionOptional. Specified hours. Optional. prescribed points. Optional. Specifies seconds. Optional. Specified month. Optional. Specify days. is_dstNote: Recommended study: "
hour
minute
second
month
day
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). This parameter is deprecated in PHP 5.1.0. Instead, new time zone handling features are used.
PHP Video Tutorial

"

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn