每天的0点php,使用strtotime,这个月的第一天凌晨0点在PHP?(Using just strtotime, 0 am first day of this month in PHP?)...

使用strtotime,这个月的第一天凌晨0点在PHP?(Using just strtotime, 0 am first day of this month in PHP?)

echo mydate(strtotime('1 am first day of this month'));

以上工作结果2017-10-01 01:00:00 ,但我很难在凌晨0点做到。 24am, 24pm, 0pm, first second工作。

echo mydate(strtotime('1 am first day of this month'));

Above works with result 2017-10-01 01:00:00, but I have difficulty to do it for 0 am. Neither 24am, 24pm, 0pm, first second works.

原文:https://stackoverflow.com/questions/46974127

更新时间:2019-12-08 15:31

最满意答案

使用midnight :

echo mydate(strtotime('midnight first day of this month'));

Use midnight:

echo mydate(strtotime('midnight first day of this month'));

2017-10-27

相关问答

你应该使用mktime()函数: <?php

echo date('Y-m-d', mktime(0,0,0,date('n')-1,1,date('Y'))); //2012-03-01

?>

请参阅实际操作 You should use the mktime() function: <?php

echo date('Y-m-d', mktime(0,0,0,date('n')-1,1,date('Y'))); //2012-03-01

?>

See In Action

尝试这个: $dates = array("10 October 13:23", "12 November 08:12", "10 October 13:23");

foreach($dates as $d){

$exploded = explode(" ", $d);

$newDate = array_slice($exploded, 0,2,true)+array(2=>"2012")+array(3 => $exploded[2]);

...

使用midnight : echo mydate(strtotime('midnight first day of this month'));

演示 Use midnight: echo mydate(strtotime('midnight first day of this month'));

Demo

每月使用j ,而不是n是数字月份: php $date = date('l, F j, Y', strtotime($this->input->post('date')));

在行动中看到它 Use j for day of the month, not n which is the numeric month: php $date = date('l, F j, Y', strtotime($this->input->post('date')));

See it in action

这是不同版本的PHP的问题。 在php 5.2.7中有一个BC,来自文档 : 在5.2.7之前的PHP 5中,请求在该工作日是该月的第一天的一个月中给定工作日的给定事件将错误地将一周添加到返回的时间戳。 这已在5.2.7及更高版本中得到纠正。 演示 服务器A的PHP> 5.2.7,服务器B的PHP <5.2.7。 This is a problem with different version of php. There is a BC in php 5.2.7, from the documen

...

这部分无关 - 问题被编辑 由于时区差异。 $ start是在'Rainy River时区'计算的,而$ middle和$ end是UTC时间。 “雨河时区与UTC的时差为-06:00小时 (正好是第一次与第二次和第三次结果之差)。 更新1 - 解决方案 看来问题出现在时间周围的某个地方。 由于某种原因,它会产生一天的偏差(需要进一步解释)。 一个简单的解决方案是从该日期减去一秒钟,它会产生正确的结果。 $timezone = new DateTimeZone('UTC');

$start = n

...

那么,关键字“的”是解决方案, strtotime(“2016-01”的第一个星期五)输出1.1.2016 Well, the keyword "of" is the solution, strtotime("first friday of 2016-01") outputs 1.1.2016

您发布的代码以您描述的方式失败; 似乎PHP手册页中的描述(正如SilentGhost所提到的,只是用户注释)是未经过验证的代码。 如果您需要某个特定月份的最后一天,请尝试以下操作: date('Y-m-d', strtotime("2009-12 next month - 1 hour"));

The code you posted fails in the manner you described; it seems that the description in the PHP manua

...

您在尝试检索该月的第一天时缺少关键字 echo date('Y-m-d', strtotime('First Monday of '.date('F o', strtotime("-4 months")));

我找到了这个bug报告的信息 我目前的版本是PHP 5.4.4,以防它仍然不适合你 You are missing the keyword of when trying to retrieve the first day of the month echo date('Y-m-d', st

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值