<bdo id='0YQMA'></bdo><ul id='0YQMA'></ul>

    <tfoot id='0YQMA'></tfoot>

    1. <legend id='0YQMA'><style id='0YQMA'><dir id='0YQMA'><q id='0YQMA'></q></dir></style></legend>
    2. <small id='0YQMA'></small><noframes id='0YQMA'>

      <i id='0YQMA'><tr id='0YQMA'><dt id='0YQMA'><q id='0YQMA'><span id='0YQMA'><b id='0YQMA'><form id='0YQMA'><ins id='0YQMA'></ins><ul id='0YQMA'></ul><sub id='0YQMA'></sub></form><legend id='0YQMA'></legend><bdo id='0YQMA'><pre id='0YQMA'><center id='0YQMA'></center></pre></bdo></b><th id='0YQMA'></th></span></q></dt></tr></i><div id='0YQMA'><tfoot id='0YQMA'></tfoot><dl id='0YQMA'><fieldset id='0YQMA'></fieldset></dl></div>

      从日期减去一定数量的小时、天、月或年

      Subtracting a certain number of hours, days, months or years from date(从日期减去一定数量的小时、天、月或年)

        <tfoot id='CRIqb'></tfoot>
        • <bdo id='CRIqb'></bdo><ul id='CRIqb'></ul>
              <legend id='CRIqb'><style id='CRIqb'><dir id='CRIqb'><q id='CRIqb'></q></dir></style></legend>

              1. <small id='CRIqb'></small><noframes id='CRIqb'>

                <i id='CRIqb'><tr id='CRIqb'><dt id='CRIqb'><q id='CRIqb'><span id='CRIqb'><b id='CRIqb'><form id='CRIqb'><ins id='CRIqb'></ins><ul id='CRIqb'></ul><sub id='CRIqb'></sub></form><legend id='CRIqb'></legend><bdo id='CRIqb'><pre id='CRIqb'><center id='CRIqb'></center></pre></bdo></b><th id='CRIqb'></th></span></q></dt></tr></i><div id='CRIqb'><tfoot id='CRIqb'></tfoot><dl id='CRIqb'><fieldset id='CRIqb'></fieldset></dl></div>
                  <tbody id='CRIqb'></tbody>

              2. 本文介绍了从日期减去一定数量的小时、天、月或年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试创建一个简单的函数,它返回一个从现在开始减去一定天数的日期,所以像这样,但我不太了解日期类:

                I'm trying to create a simple function which returns me a date with a certain number of subtracted days from now, so something like this but I dont know the date classes well:

                <?
                function get_offset_hours ($hours) {
                    return date ("Y-m-d H:i:s", strtotime (date ("Y-m-d H:i:s") /*and now?*/));
                }
                
                function get_offset_days ($days) {
                    return date ("Y-m-d H:i:s", strtotime (date ("Y-m-d H:i:s") /*and now?*/));
                }
                
                function get_offset_months ($months) {
                    return date ("Y-m-d H:i:s", strtotime (date ("Y-m-d H:i:s") /*and now?*/));
                }
                
                function get_offset_years ($years) {
                    return date ("Y-m-d H:i:s", strtotime (date ("Y-m-d H:i:s") + $years));
                }
                
                print get_offset_years (-30);
                ?>
                

                是否可以做类似的事情?这种功能可以使用多年,但其他时间类型如何做到这一点?

                Is it possible to do something similar to this? this kind of function works for years, but how to do the same with other time types?

                推荐答案

                几个小时:

                function get_offset_hours($hours)
                {
                    return date('Y-m-d H:i:s', time() + 3600 * $hours);
                }
                

                类似的东西在几个小时和几天内都可以正常工作(几天使用 86400),但是对于几个月和一年来说,它有点棘手......

                Something like that will work well for hours and days (use 86400 for days), but for months and year it's a bit trickier...

                你也可以这样做:

                $date = strtotime(date('Y-m-d H:i:s') . ' +1 day');
                $date = strtotime(date('Y-m-d H:i:s') . ' +1 week');
                $date = strtotime(date('Y-m-d H:i:s') . ' +2 weeks');
                $date = strtotime(date('Y-m-d H:i:s') . ' +1 month');
                $date = strtotime(date('Y-m-d H:i:s') . ' +30 days');
                $date = strtotime(date('Y-m-d H:i:s') . ' +1 year');
                
                echo(date('Y-m-d H:i:s', $date));
                

                这篇关于从日期减去一定数量的小时、天、月或年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <tbody id='qjdi7'></tbody>

                    <bdo id='qjdi7'></bdo><ul id='qjdi7'></ul>
                  • <i id='qjdi7'><tr id='qjdi7'><dt id='qjdi7'><q id='qjdi7'><span id='qjdi7'><b id='qjdi7'><form id='qjdi7'><ins id='qjdi7'></ins><ul id='qjdi7'></ul><sub id='qjdi7'></sub></form><legend id='qjdi7'></legend><bdo id='qjdi7'><pre id='qjdi7'><center id='qjdi7'></center></pre></bdo></b><th id='qjdi7'></th></span></q></dt></tr></i><div id='qjdi7'><tfoot id='qjdi7'></tfoot><dl id='qjdi7'><fieldset id='qjdi7'></fieldset></dl></div>

                        <legend id='qjdi7'><style id='qjdi7'><dir id='qjdi7'><q id='qjdi7'></q></dir></style></legend>
                      • <tfoot id='qjdi7'></tfoot>

                          <small id='qjdi7'></small><noframes id='qjdi7'>