从现在开始接下来的10个月? [英] Getting the next 10th of a month from now?

查看:80
本文介绍了从现在开始接下来的10个月?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从今天开始,我试图找到一个月的下个十日。所以如果今天是五月二十七日,下一个十号是六月十号。如果今天是8月1日,下一个10日将是8月10日的例子。

I am trying to find the next 10th of a month starting with today. So if today is the 27th of May, the next 10th is the 10th of June. If today is the 1st of August, the next 10th will be the 10th of August for example.

我知道我可以在下个月的第一天使用



I know I can find the first day of the next month using

$firstDayNextMonth = date('Y-m-d', strtotime('first day of next month'));

我可以将这种格式用于我的案例吗?如果没有,我该如何实现我的目标?

Can I use that format for my case as well? If not, how could I achieve my goal?

非常感谢您的帮助! :)

Thanks a lot for helping! :)

推荐答案

strtotime 不能在一次通话,但您可以执行以下操作:

strtotime is not able to do this in one call, but you could do something like:

<?php
    $current_day = (int)date('j');

    if ($current_day < 10) {
        $firstDayNextMonth = date('Y-m-d', strtotime('+9 days', strtotime('first day of this month')));
    } else {
        $firstDayNextMonth = date('Y-m-d', strtotime('+9 days', strtotime('first day of next month')));
    }

    echo $firstDayNextMonth;
?>

或仅仅是

$firstDayNextMonth = date('Y-m-d', strtotime('+9 days', strtotime('first day of ' . ((int)date('j') < 10 ? 'this' : 'next' ) . ' month')));

这篇关于从现在开始接下来的10个月?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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