How to convert Chinese date to timestamp in php

藏色散人
Release: 2023-03-09 17:26:01
Original
2390 people have browsed it

php Method to convert Chinese date to timestamp: First create a PHP sample file; then use "date_parse_from_format" and "mktime function" to convert the Chinese year, month and day date into a timestamp.

How to convert Chinese date to timestamp in php

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

php processes the date containing Chinese year, month and day and converts it to a timestamp (for example, November 08, 2017 to a timestamp)

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 of November 8th is: 1510070400

date_parse_from_formatDefinition and usage

date_parse_from_format() function returns the association containing the specified date information according to the specified format array.

Syntax

date_parse_from_format(format,date);
Copy after login
Parameters Description
format Required. Specifies the format (formats accepted by date_create_from_format()).
date Required. Specify date as a string value.

ktime()定义和用法

gmmktime() 函数返回日期的 UNIX 时间戳。

提示:该函数与 gmmktime() 相同,不同的是传递的参数代表了日期(而不是 GMT 日期)。

语法

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

year可选。规定年。

参数 描述
hour 可选。规定小时。
minute 可选。规定分。
second 可选。规定秒。
month 可选。规定月。
day 可选。规定天。


is_dst

可选。如果时间在夏令时 (DST) 期间,则设置为 1,否则设置为 0,若未知则设置为 -1(默认)。

如果未知,PHP 会自己进行查找(可能产生意外的结果)。

注意:该参数在 PHP 5.1.0 中被废弃。取而代之使用的是新的时区处理特性。

Copy after login

输出

Jan-05-2002 Feb-01-2002 Jan-01-2001 Jan-01-1999 PHP time() 函数 PHP Date / Time 函数
Copy after login

推荐学习:《PHP视频教程

The above is the detailed content of How to convert Chinese date to timestamp in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!