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

青灯夜游
Release: 2023-03-09 09:10:01
Original
2385 people have browsed it

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;
?>
Copy after login

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);
Copy after login

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);
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template