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条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程