在PHP中获取给定月份和年份的开始和结束Unix时间戳 [英] Get the beginning and ending unix timestamp for a given month and year in php

查看:267
本文介绍了在PHP中获取给定月份和年份的开始和结束Unix时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查找一个月第一天(例如2010年9月1日和0:00)和一个月最后一天(例如9月31日23:59)的时间戳.

I want to find the timestamp for the first day in a month (say September 1 2010 and 0:00) and the last day in a month (say September 31 23:59).

推荐答案

如果将这些日期作为字符串,则可以简单地使用 strtotime (),如果您只有部分信息,则可以使用 mktime().

If you have those dates as strings you can simply use strtotime(), if you have only partial information you can use mktime().

但是,9月只有30天;)

However, September only has 30 days ;)

示例:

$month = 9;
$year  = 2010;

$first = mktime(0,0,0,$month,1,$year);
echo date('r', $first);

$last = mktime(23,59,00,$month+1,0,$year);
echo date('r', $last);

这篇关于在PHP中获取给定月份和年份的开始和结束Unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆