【问题标题】:Time picker format changes ,When inserting into database时间选择器格式更改,插入数据库时
【发布时间】:2018-09-06 04:27:05
【问题描述】:

查看:

<div class="col-sm-6">
  <input type="text" class="form-control timepicker" name="shiftStartTime" id="shiftStartTime" required parsley-maxlength="6" placeholder="Shift Start Time" />
</div>

脚本

<script type="text/javascript">
$(document).ready(function(){

   $('.timepicker').wickedpicker();

    });   

</script>

控制器代码:

$shiftstarttime = $this->input->post('shiftStartTime');

但它以“00:00:12”的形式插入数据库。如何将其更改为 H:m:s 格式(即 12:05:10)

【问题讨论】:

  • 数据库中的列类型是什么?
  • 它的时间类型......
  • 请使用strtotime php函数

标签: php database codeigniter timepicker


【解决方案1】:

试试这个 它给了你正确的价值

<input type="text" class="form-control timepicker" name="shiftStartTime" id="shiftStartTime" required placeholder="HH:MM:SS" />

脚本

<script type="text/javascript">
    $('.timepicker').timepicker({
         'timeFormat': 'H:i:s',
    });
</script>

控制器代码

$shiftstarttime = $this->input->post('shiftStartTime');

确保数据库中的列类型是时间

【讨论】:

    【解决方案2】:

    首先,您需要确认在帖子中您获得了正确的值,如果是,那么以下内容对您有用

    $input = $this->input->post('shiftStartTime');
    $input = str_replace(" : ", ":", $input);
    $shiftstarttime = date('H:i:s', strtotime($input));
    

    【讨论】:

    • 通过使用这种方法,即使插入了任何时间,时间都存储在数据库中为 05:30:00。
    • 在插入数据库之前得到什么值。什么是岗位价值?请先打印出来看看里面的值是多少?
    • 输入值正确。我刚打印出来。但是输入数据库的值是错误的
    • 能否请您告诉我您打印的输入值中的格式是什么?
    • 例如:5 : 37 PM
    【解决方案3】:

    首先,检查您何时获得时间形式的日期选择器,它是以哪种形式出现的。

    否则,您可以在控制器端专门更改格式,然后将该值分配给数据库对象。

    【讨论】:

      【解决方案4】:

      试试这个,希望对你有用。

      <script>
      $(document).ready(function(){
          $('.timepicker').timepicker({});
      });
      </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-21
        • 1970-01-01
        • 2017-03-24
        • 2013-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多