[英]PHP time, include the first day
I have a timestamp in a MySql database. 我在MySql数据库中有一个时间戳。 The format is: 2018-08-28 12:39:59 格式为:2018-08-28 12:39:59
I want to select different periods of time. 我想选择不同的时间段。 I have problems with the time part. 我的时间部分有问题。 For instance: 例如:
$begin = strtotime("first day of this month midnight");
$begin = date("Y-m-d h:i:s", $begin);
If I echo $begin it gives me: 2018-08-01 12:00:00 如果我回显$ begin它会给我:2018-08-01 12:00:00
So, it does not includes for instance: 2018-08-01 01:00:00 因此,它不包括例如:2018-08-01 01:00:00
I have been searching and the official documentation says: 我一直在搜索,官方文档说:
'midnight' The time is set to 00:00:00 “午夜”时间设置为00:00:00
http://php.net/manual/en/datetime.formats.relative.php http://php.net/manual/en/datetime.formats.relative.php
How to include the whole first day in the begin variable? 如何将整个第一天包括在begin变量中? (begin from 0 or ignore time) (从0开始或忽略时间)
You are using the wrong hour format, you should do: 您使用了错误的小时格式,您应该这样做:
// uppercase H --v
$begin = date("Y-m-d H:i:s", $begin);
// Output: 2018-08-01 00:00:00
echo $begin;
From the documentation : 从文档中 :
h
: 12-hour format of an hour with leading zeros h
:小时的12小时格式,前导零 H
: 24-hour format of an hour with leading zeros H
:小时的24小时制,前导零 PHP's date function has two different modifiers: H and hh displays hour in a 12-hour format (so midnight is 12... if you added the AM/PM modifier you'd see 12:00:00 am) PHP的date函数具有两个不同的修饰符:H和hh以12小时格式显示小时(因此午夜为12 ...如果添加了AM / PM修饰符,则会看到12:00:00 am)
try 尝试
$begin = date("Y-m-d H:i:s", $begin);
The will output 00:00:00 as you expect 将会输出您期望的00:00:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.