dongshubang7816 2018-08-16 17:49
浏览 203
已采纳

在Laravel输入字段中将AM / PM转换为24小时制

Problem: I'm using laravel forms in combination with Carbon to try and pass a date value to my database. I'm trying to switch the input field format to 24 hours instead of AM/PM, but I keep getting the standard AM/PM format. I tried ->format() but didn't find the correct solution.

Question: How can I replace the AM / PM Format of the input field to the 24 hours clock?

My code:

{{Form::date('date', \Carbon\Carbon::now(),['class' => 'form-control'])}}
{{Form::time('time', \Carbon\Carbon::now()->timezone('Europe/Brussels'),['class' => 'form-control'])}}

// Input field values:

// Date: 08/16/2018 , Time: 07:47 PM -> 19:47:00

Input result when changing the format:

{{Form::time('time', \Carbon\Carbon::now()->timezone('Europe/Brussels')->format('H:i:s'),['class' => 'form-control'])}}

// Input value of time:
// Time: 08:00:29 PM 
  • 写回答

2条回答 默认 最新

  • dongliqian6245 2018-08-16 17:53
    关注

    You'll need to change your time field to the following

    {{Form::time('time', \Carbon\Carbon::now()->timezone('Europe/Brussels')->format('H:i:s'),['class' => 'form-control'])}}
    

    To explain the formatting;
    H - 24 Hour with trailing zeros
    i - Minutes with trailing zeros
    s - Seconds with trailing zeros

    You can see all the date/time variables at PHP Date

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用