Laravel Nova中是否有选项显示可读的日期时间输出和/或限制输出?
例如:2018年10月29日/ 11. 2018年11月,上午12:10
码:
DateTime::make('Start')
->rules('required')
->sortable(),
使用这个,希望它会起作用
Date::make('start')->format('F j, Y'),
根据文件https://nova.laravel.com/docs/1.0/resources/fields.html#datetime-field
use Laravel\Nova\Fields\DateTime;
DateTime::make('Start')->format('DD MMMM YYYY'),
必须使用Moment.js格式规则https://momentjs.com/docs/#/displaying/format/
我们也遇到了这样的问题。这个解决方案DateTime :: make('Start') - > format('DD MMMM YYYY'),仅对索引页有帮助,但对Edit页没有帮助。我不知道什么时候这个bug会在新的Nova版本中修复,但是我们暂时使用了小的硬编码。
instead: return $value->format('Y-m-d'); use this one: return $value->format('m/d/Y');
In this vue component also should be changed a date format: dateFormat="m/d/Y".
For placeholder method use this one: return this.field.placeholder || moment().format('MM/DD/YYYY') Instead this: return this.field.placeholder || moment().format('YYYY-MM-DD')
public function setLastUsedAttribute($value){ $date = Carbon::createFromFormat('m/d/Y', $value); $this->attributes['last_used'] = $date->format('Y-m-d'); }