Home > Backend Development > PHP Tutorial > How to get the timestamp of the beginning and end of a specified month using php

How to get the timestamp of the beginning and end of a specified month using php

little bottle
Release: 2023-04-06 09:10:01
forward
4525 people have browsed it

This article mainly talks about using php to obtain the timestamps at the beginning and end of a specified month. It has certain reference value. Interested friends can learn about it.

How to get the timestamp of the beginning and end of a specified month using php

Get the start timestamp and end timestamp of the specified month, just pass in the year and month (both formats 2018-01 and 2018-1 are acceptable), The code is as follows:

$data['sel_time'] = '2018-11';
$data['begin_time'] = strtotime($data['sel_time']);        //指定月份的开始时间戳
$data['end_time'] = mktime(23,59,59,date('m',strtotime($data['sel_time']))+1,00);  //指定月份月末时间戳 

echo $data['begin_time']."<br>".$data['end_time'];
Copy after login

Result:

Related tutorials: PHP video tutorial

The above is the detailed content of How to get the timestamp of the beginning and end of a specified month using php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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 Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template