- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试在 laravel 5.2 中使用德语的 Carbon 的 diffForHumans()
显示 created_at
属性。created_at
在数据库中存储为:2017-03-29 17:31:52
模型
protected $dates = ['created_at', 'updated_at'];
public static function getCreatedAtAttribute($value)
{
Carbon::setLocale('de');
return Carbon::parse($value, 'Europe/Berlin')->diffForHumans();
}
dd($value);
返回 "2017-03-29 17:31:52"
。
观点
@foreach($posts as $post)
<small>{{ $post->getCreatedAtAttribute($post->created_at) }}</small>
@endforeach
错误
DateTime::__construct(): Failed to parse time string (vor 3 Tagen) at position 0 (v): The timezone could not be found in the database
如果有任何帮助,我将不胜感激!
最佳答案
对于德语翻译,我在 AppServiceProvider 中使用了这个定制:
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
// Localization Carbon
\Carbon\Carbon::setLocale(config('app.locale'));
}
}
使用此设置,数据显示为:vor 3 Tagen
而不是 3 days ago
。
关于php - Laravel - diffForHumans 德语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43168444/
我的MySQL中有一个字段表fecha作为日期时间,我想对其应用适当的格式,然后使用 diffForHumans 获得差异但它显示错误 "message": "The separation symbo
我正在尝试以“5 小时”、“50 分钟”等格式获取日期。我正在从 api 获取数据,格式为:2015-12-16 19:28 :16 我成功地接收到变量中的值: let date = post["cr
在我的表中设置一个时间戳字段,以便在字段中创建和更新。 然后在我的模型中我这样做: protected $dates = ['created_at', 'updated_at']; 但是调用日期时:
我正在尝试在 laravel 5.2 中使用德语的 Carbon 的 diffForHumans() 显示 created_at 属性。 created_at 在数据库中存储为:2017-03-29
怎么修剪diffForHumans() ? 赞 $post->created_at->diffForHumans()返回前一段时间 赞 3 days ago或 57 minutes ago , 或 2
我正在尝试找出如何缩短 laravel 中 Carbon 库提供的 diffForHumans 方法的输出。 diffForHumans 的默认格式如下所示:(来自文档) 将过去的值与现在的默认值进行
我正在尝试在我的项目中实现评论部分,并希望显示评论发布的时间。 所以我做了: {{ $comment->created_at->diffForHumans() }} 输出是 3 hours fr
我想使用 Carbon 显示一个日期的天数和小时数,目前我得到了下面的代码。 Carbon::parse("2017-03-07 17:46:50")->diffForHumans() 输出: 6 d
在 string.. 上调用成员函数 diffForHumans()我实际上在做的是在 Blade 中获取的日期调用 diffForHumans。 {{$data['date']->diffForHu
为什么当我使用查询生成器而不是函数 diffForHumans () 时出现错误,但是如果我使用 ELoquent ROM 但没有错误有办法克服它吗? (我该如何解决)谢谢 diffForHumans
首先我使用 Carbon\Carbon;然后我尝试回应 doc 的 difforhumans 引用:https://carbon.nesbot.com/docs/#api-humandiff echo
根据手册:http://carbon.nesbot.com/docs/#api-humandiff 获取一个ago When comparing a value in the past to defa
我是一名优秀的程序员,十分优秀!