无法在laravel中编辑日期格式

时间:2017-07-19 09:27:52

标签: php laravel

我在laravel非常新,现在,我正在建立一个编辑表格,出生日期将始终是时间" 1-1-1970"每当我想改变它。

我的代码出了什么问题?

<div class="form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="date_of_bday">
        Date Of Birthday
        <span class="required">*</span>
    </label>
    <div class="col-md-6 col-sm-6 col-xs-12">
         <input id="single_cal1" type="text" class="form-control has-feedback-left @if($errors->has('date_of_bday')) parsley-error @endif"
                           name="date_of_bday" placeholder="Date Of Birthday" aria-describedby="inputSuccess2Status" value="{{ date('m/d/Y', strtotime($member->dob)) }}" required>
         <span class="fa fa-calendar form-control-feedback left" aria-hidden="true"></span>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

使用Carbon解析日期并相应地格式化

<div class="form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="date_of_bday">
        Date Of Birthday
        <span class="required">*</span>
    </label>
    <div class="col-md-6 col-sm-6 col-xs-12">
         <input id="single_cal1" type="text" class="form-control has-feedback-left 
         @if($errors->has('date_of_bday')) parsley-error @endif" 
         name="date_of_bday" 
         placeholder="Date Of Birthday" 
         aria-describedby="inputSuccess2Status" 
         value="{{ Carbon\Carbon::parse($member->dob)->format('m/d/Y') }}" 
         required>
         <span class="fa fa-calendar form-control-feedback left" aria-hidden="true"></span>
    </div>
</div>