Home  >  Article  >  Backend Development  >  How to convert Chinese date string to time format in php

How to convert Chinese date string to time format in php

藏色散人
藏色散人Original
2023-02-20 09:34:463368browse

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)


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 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);

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);
year is optional. Specified year.

How to convert Chinese date string to time format in php


Output
Jan-05-2002
  
Feb-01-2002
  
Jan-01-2001
  
Jan-01-1999
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!

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