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

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

        将分钟添加到日期时间无法正常工作

        Adding minutes to date time not working properly(将分钟添加到日期时间无法正常工作)

          <tbody id='ecgFw'></tbody>
        <legend id='ecgFw'><style id='ecgFw'><dir id='ecgFw'><q id='ecgFw'></q></dir></style></legend>
        <i id='ecgFw'><tr id='ecgFw'><dt id='ecgFw'><q id='ecgFw'><span id='ecgFw'><b id='ecgFw'><form id='ecgFw'><ins id='ecgFw'></ins><ul id='ecgFw'></ul><sub id='ecgFw'></sub></form><legend id='ecgFw'></legend><bdo id='ecgFw'><pre id='ecgFw'><center id='ecgFw'></center></pre></bdo></b><th id='ecgFw'></th></span></q></dt></tr></i><div id='ecgFw'><tfoot id='ecgFw'></tfoot><dl id='ecgFw'><fieldset id='ecgFw'></fieldset></dl></div>
          • <small id='ecgFw'></small><noframes id='ecgFw'>

            • <bdo id='ecgFw'></bdo><ul id='ecgFw'></ul>

                  <tfoot id='ecgFw'></tfoot>
                  本文介绍了将分钟添加到日期时间无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发 Yii2.在其中,我试图将数据插入 3 个不同的阶段.即我正在使用 3 个查询一个接一个地插入不同类型的数据.数据插入是完美的,但日期时间不是.由于我想连续添加数据,所以我添加了一个 for 循环.但是它插入的日期时间总是相同的.在下面查看我的代码

                  I am working on Yii2. In it I am trying to insert data into 3 different stages. i.e. I am using 3 queries one by one to insert different types of data. The data insertion is perfect but date-time is not. As I want to add data continuously so I have added a for loop. But the date-time it's inserting is always the same. See my code below

                  for ($i = 0; $i <= 60; $i++) 
                  {
                    $dt = date('Y-m-d H:i:s');
                   $model401->data_date_time = date('Y-m-d H:i:s', strtotime('+5 minutes', strtotime($dt)));
                   $model402->data_date_time = date('Y-m-d H:i:s', strtotime('+10 minutes', strtotime($dt)));
                   $model403->data_date_time = date('Y-m-d H:i:s', strtotime('+15 minutes', strtotime($dt)));
                  .
                  .
                  .
                  .
                  .
                  .
                  }
                  

                  保存在数据库中的日期时间相同,即

                  The date-time is saving in DB is same i.e.

                  2020-04-25 11:11:57 首创日期

                  2020-04-25 11:16:57 第二个记录日期

                  2020-04-25 11:21:57 第三次记录日期

                  2020-04-25 11:11:57 第四次记录日期

                  2020-04-25 11:16:57 第五记录日期

                  2020-04-25 11:21:57 第六记录日期

                  表格视图

                  更新 1

                  for($i=0; $i<=60; $i++)
                  {
                  try {
                              $cust_met_data = Yii::$app->db->createCommand(
                              /** @lang text */ "SELECT m.`meter_id` , m.`msn` , 
                                    m.`cust_id` , m.`device_id` FROM `mdc_meter_cust_rel` m ")->queryAll();
                          } catch (Exception $e) {
                          }
                  
                          $slave_id = $cust_met_data[0]['device_id'];
                          $address = 0;
                          $count = 14;
                          $msn = $cust_met_data[0]['msn'];
                          $cust_id = $cust_met_data[0]['cust_id'];
                  
                          // my base URL
                          $api_url = 'https://localhost:44337/api/rtu/GetData/' . $slave_id . '/' . $address . '/' . $count;
                  
                  
                          $curl = curl_init($api_url);
                  
                          curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                          curl_setopt($curl, CURLOPT_TIMEOUT, 1000);
                          curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
                          curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
                  
                          $curl_response = curl_exec($curl);
                  
                          $json = json_decode($curl_response);
                  
                          if ($json->{0} == '06') {
                              echo " line 1656 ";
                              echo " An error occurs ";
                  
                              //return $this->redirect(['index']);
                          } else {
                              echo " line 1663 ";
                              $vol_1 = $json->{0};
                              $vol_2 = $json->{1};
                              $vol_3 = $json->{2};
                              $curr_1 = $json->{3};
                              $curr_2 = $json->{4};
                              $curr_3 = $json->{5};
                              $kwh = $json->{6};
                  
                              $dt =  date('Y-m-d H:i:s');
                              $currDt = date('Y-m-d H:i:s', strtotime('+5 minutes', strtotime($dt)));
                              $volDt = date('Y-m-d H:i:s', strtotime('+10 minutes', strtotime($dt)));
                              $kwhDt = date('Y-m-d H:i:s', strtotime('+15 minutes', strtotime($dt)));
                              $typeCurr = "401";
                              $typeVol = "402";
                              $typeKwh = "403";
                  
                              /***** for current *****/
                              echo " adding current values ";
                  
                              $model401 = new MdcmetersData();
                             // $model401->load(Yii::$app->request->post());
                              $model401->data_date_time = date('Y-m-d H:i:s', strtotime('+5 minutes', strtotime($dt)));
                              $model401->device_id = $slave_id;
                              $model401->msn = $msn;
                              $model401->cust_id = $cust_id;
                              $model401->voltage_p1 = "";
                              $model401->voltage_p2 = "";
                              $model401->voltage_p3 = "";
                              $model401->current_p1 = $curr_1;
                              $model401->current_p2 = $curr_2;
                              $model401->current_p3 = $curr_3;
                              $model401->kwh = "";
                              $model401->d_type = "401";
                              $model401->save();
                  
                  
                              /***** for voltages *****/
                              echo " adding voltages values ";
                  
                  
                              $model402 = new MdcmetersData();
                              //$model402->load(Yii::$app->request->post());
                              $model402->data_date_time = date('Y-m-d H:i:s', strtotime('+10 minutes', strtotime($dt)));
                              $model402->device_id = $slave_id;
                              $model402->msn = $msn;
                              $model402->cust_id = $cust_id;
                              $model402->voltage_p1 = $vol_1;
                              $model402->voltage_p2 = $vol_2;
                              $model402->voltage_p3 = $vol_3;
                              $model402->current_p1 = "";
                              $model402->current_p2 = "";
                              $model402->current_p3 = "";
                              $model402->kwh = "";
                              $model402->d_type = "402";
                              $model402->save();
                  
                  
                              /***** for kwh *****/
                              echo " adding kwh values ";
                  
                              $model403 = new MdcmetersData();
                             // $model403->load(Yii::$app->request->post());
                              $model403->data_date_time = date('Y-m-d H:i:s', strtotime('+15 minutes', strtotime($dt)));
                              $model403->device_id = $slave_id;
                              $model403->msn = $msn;
                              $model403->cust_id = $cust_id;
                              $model403->voltage_p1 = "";
                              $model403->voltage_p2 = "";
                              $model403->voltage_p3 = "";
                              $model403->current_p1 = "";
                              $model403->current_p2 = "";
                              $model403->current_p3 = "";
                              $model403->kwh = $kwh;
                              $model403->d_type = "403";
                              $model403->save();
                  
                  
                          }
                  
                      }
                      }
                  

                  您可以看到第一个到第三个和第四个到第六个日期时间是相同的.如何准确设置日期时间?

                  You can see that first to 3rd and fourth to sixth date-time are the same. How can I set the date-time accurately?

                  任何帮助将不胜感激.

                  推荐答案

                  自定义:

                  $dt = date('Y-m-d H:i:s');
                  echo $dt . '<br>'; //now
                  $min5Later = strtotime('+5 minutes', strtotime($dt));//5 min later from $dt
                  $min5LaterFormat = date('Y-m-d H:i:s', $min5Later);
                  
                  $min10Later = strtotime('+10 minutes', strtotime($dt));//10 min later from $dt
                  $min10LaterFormat = date('Y-m-d H:i:s', $min10Later);
                  
                  $min15Later = strtotime('+15 minutes', strtotime($dt));//15 min later from $dt
                  $min15LaterFormat = date('Y-m-d H:i:s', $min15Later);
                  
                  for ($i = 0; $i <= 2; $i++) {
                      $min5Later = strtotime('+5 minutes', strtotime($min5LaterFormat));//5 min later from $min5later
                      $min5LaterFormat = date('Y-m-d H:i:s', $min5Later);
                      $min10Later = strtotime('+10 minutes', strtotime($min10LaterFormat));//10 min later from $min10later
                      $min10LaterFormat = date('Y-m-d H:i:s', $min10Later);
                      $min15Later = strtotime('+15 minutes', strtotime($min15LaterFormat));//15 min later from $min15later
                      $min15LaterFormat = date('Y-m-d H:i:s', $min15Later);
                  
                   echo $min5LaterFormat . ' | ';
                   echo $min10LaterFormat . ' | ';
                   echo $min15LaterFormat . ' | <br>';
                  }
                  

                  输出:

                  2020-05-10 19:19:47
                  2020-05-10 19:29:47 | 2020-05-10 19:39:47 | 2020-05-10 19:49:47 |
                  2020-05-10 19:34:47 | 2020-05-10 19:49:47 | 2020-05-10 20:04:47 |
                  2020-05-10 19:39:47 | 2020-05-10 19:59:47 | 2020-05-10 20:19:47 |
                  

                  这篇关于将分钟添加到日期时间无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is Joomla 2.5 much faster than Joomla 1.5 Querywise(Joomla 2.5 比 Joomla 1.5 Querywise 快得多吗)
                  How to share Joomla login session from one joomla website to one ASP.Net MVC website(如何将 Joomla 登录会话从一个 joomla 网站共享到一个 ASP.Net MVC 网站)
                  htaccess redirect root to subdirectory but allow index.php in root AND query strings to function(htaccess 将根重定向到子目录,但允许根和查询字符串中的 index.php 起作用)
                  Joomla include database functions(Joomla 包含数据库功能)
                  nl2br() not working when displaying SQL results(显示 SQL 结果时 nl2br() 不起作用)
                  Joomla 2.5 JFactory::getSession(); seems to be caching in firefox(Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存)

                    1. <tfoot id='B20Y7'></tfoot>

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

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