search
HomeBackend DevelopmentPHP ProblemHow to convert year, month and day to timestamp in php

Method for converting year, month and day to timestamp: 1. Use the date_parse_from_format() function to process a given date. An associative array containing the specified date information will be returned according to the specified format. The syntax is "date_parse_from_format('Y.m.d ', date)"; 2. Use the "mktime(0,0,0,$arr['month'],$arr['day'],$arr['year']);" statement to convert the year, month and day Just a timestamp.

How to convert year, month and day to timestamp in php

The operating environment of this article: windows7 system, PHP8 version, DELL G3 computer

PHP specified date to timestamp

Use date_parse_from_format to convert the specified format: For example:

<?php
$str = &#39;2018.10.01&#39;;//或者 2018年10月1日
$arr = date_parse_from_format(&#39;Y.m.d&#39;,$str);//如果是2018年10月1日,那么这里就是 Y年m月d日
$time = mktime(0,0,0,$arr[&#39;month&#39;],$arr[&#39;day&#39;],$arr[&#39;year&#39;]);
print_r($arr);
echo &#39;对应时间戳为:&#39;.$time;

Output:

Array ( [year] => 2018 [month] => 10 [day] => 1 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => )
 对应时间戳为:1538352000

mktime() 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).

Syntax

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

year Optional. Specified year.

ParametersDescriptionhourOptional. Specified hours. minuteOptional. prescribed points. secondOptional. Specifies seconds. monthOptional. Specified month. day Optional. Specify days. is_dst
Optional. Set to 1 if the time is during Daylight Saving Time (DST), 0 otherwise, or -1 (default) if unknown.

If unknown, PHP will do the search itself (which may produce unexpected results).

Note: This parameter is deprecated in PHP 5.1.0. Instead, new time zone handling features are used.

[Recommended learning: "

PHP Video Tutorial"]

The above is the detailed content of How to convert year, month and day to 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software