How to convert Chinese date string to time format in php

藏色散人
Release: 2023-03-17 22:02:02
Original
3515 people have browsed it

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.

How to convert Chinese date string to time format in php

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 = &#39;2017年11月08号&#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;]);
	print_r($arr);
	echo &#39;2017年11月08号对应时间戳为:&#39;.$time;
?>
Copy after login


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

2017 The corresponding timestamp for November 8th is: 1510070400

date_parse_from_format definition and usage

date_parse_from_format() 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

How to convert Chinese date string to time format in php

##ktime() definition and usage

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

Tip: This function is the same as gmmktime(), except that the parameter passed represents a date (instead of a GMT date).

Grammar

mktime(hour,minute,second,month,day,year,is_dst);
Copy after login
year is optional. Specified year.

How to convert Chinese date string to time format in php


<?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)));
?>
Copy after login
Output
Jan-05-2002
  
Feb-01-2002
  
Jan-01-2001
  
Jan-01-1999
Copy after login
Recommended learning: "

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!

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