Laravel 中設定 Carbon 的 diffForHumans 方法返回中文
在寫 feed 流功能時,經常要用到 Carbon 的 diffForHumans 方法,以方便返回直觀的時間描述。
例如
Carbon::parse($date)->diffForHumans();
- 10秒前
- 5分鐘前
但是,預設 Carbon 並不會遵守 laravel config 中的 locale,需要特別指定。
編輯 app/Providers/AppServiceProvider.php
use Carbon\Carbon;
public function boot() {
Carbon::setLocale('zh');
}
參考
https://laravel-china.org/articles/5577/the-diffforhumans-method-of-carbon
相關推薦
Laravel 中設定 Carbon 的 diffForHumans 方法返回中文
在寫 feed 流功能時,經常要用到 Carbon 的 diffForHumans 方法,以方便返回直觀的時間描述。 例如 Carbon::parse($date)->diffForHumans(); 10秒前 5分鐘前 但是,預設 Carbon 並不會遵守 laravel co
Vue專案中設定背景圖片方法
例如css樣式 background:url("../../assets/head.jpg"); 1、在data中定義如下: export default { name: 'productdetailspage', data() { return { n
tp3.2 ajaxReturm方法 返回中文時亂碼問題
tp3.2呼叫ajaxReturn中文亂碼之所以出現中文亂碼,是因為tp3.2在對資料進行轉換的時候,直接使用json_encode函式。 該該函式會將中文轉為Unicode編碼這樣就會出現亂碼。 開啟Thinkphp中Controller.class.php檔案。找到ajaxReturn方法 1
正確的在Kubernetes叢集中使用SDN技術方法_Kubernetes中文社群
SDN是Software-defined networking的縮寫。在許多介紹Kubernetes的文件,特別是安裝文件中, 當介紹到Kubernetes所需的容器網路時常常會提到這個縮寫,告知使用者需要使用某種SDN技術用以解決“每個Pod有獨立IP, Pod之間可以不經過NAT直接互訪”
最簡單的處理MVC中預設的Json方法返回時間的問題
利用 Json方法返回 資料時,如果有時間格式,會變成 “\/Date(1369419656217)\/” 這個樣子,問了同事找到個解決方法 using Newtonsoft.Json; using Newtonsoft.Json.Converters;
Eclipse中設定JVM記憶體方法
public class TestMemory { /** * @param args */ public static void main(String[] args) { System. out .println( " 記憶體資訊 :" +
在java程式碼中設定字型顏色方法總結
setTextColor(0xFF0000FF); //0xFF0000FF是int型別的資料,分組一下0x|FF|0000FF,0x是代表顏色整 數的標記,ff是表示透明度,0000FF表示顏色,注意:這裡0xFF0000FF必須是8個的顏色表示,不接受0000FF這
Allegro中設定開窗的方法 Allegro中設定開窗的方法
該文章裝載於http://www.beamsky.com/allegro-soldermask/。 最近常常看到讀者在本站搜尋開窗相關的內容,Alex特撰寫本文簡單介紹一下。開窗其實就是使銅皮裸露,通常用於遮蔽罩設計,散熱設計,接地設計等,無論是哪種設計,其操作方法都是
在IDEA中設定方法自動註釋(帶引數和返回值)
第一部分 設定 開啟設定面板 新建 線上模板 新建自動新增規則,注意 這裡觸發的字元 不能隨便寫 必須為 * Template text 區域 看上去有點亂,但是是為了顯示時的對齊,該區域的內容如下(空格之類的不要亂動): *
關於Laravel中使用response()方法呼叫json()返回資料unicode編碼轉換的問題解決
在網上找了好久沒有找到,之後一步一步測試,發現了Laravel還是很強大的,解決方案如下: public function response(){ // 返回json資料 $data = [ 'errCode'
struts2在配置文件中調用Action的方法返回值
ack 文件下載 返回 public class int cat chm webex struts2在配置文件中可以調用Action的方法返回值 1.Action中 //文件下載名 public String getDownloadFileName(){
laravel中的數據庫操作(增刪改查)方法一
-s delet 增刪 insert 修改 name tro des 命名空間 導入命名空間和DBnamespace App\Http\Controllers;use Illuminate\Support\Facades\DB; public function index
JS編程中,有時需要在一個方法返回兩個個或兩個以上的數據
簡單的 cli getname body 一個 rip itl s函數 info 轉自腳本之家: 1 使用數組的方式,如下: <html> <head> <title>JS函數返回多個值</title> </hea
JavaSE8基礎 類中的public成員方法 可以返回 private static類型的成員變量
true png 變量 珍惜 on() kill 博客 pub light 禮悟: 好好學習多思考,尊師重道存感恩。葉見尋根三二一,江河湖海同一體。 虛懷若谷良心主,願行無悔給最苦。讀書鍛煉強身心,誠勸且行且珍惜。
MVC控制器中動作方法返回的結果
clas OS 狀態碼 div () ont http hello 302跳轉 在MVC控制器中主要的返回方式有如下幾種: 1、Content(): 返回文本類型的ContentResult,比如“這是我做的一個MVC”。 2、File():
在laravel中,使用DB查詢數據庫後,返回的對象,可以用下面的辦法變為數組
UNC lar class div nod 使用 get() map account $nodes = Db::table(‘account‘)->orderBy(‘sort‘, ‘asc‘)->orderBy(‘id‘ ,‘asc‘)->get()-&g
關於Django中JsonResponse返回中文字典編碼錯誤的解決方案
keys **kwargs 技術 pytho div safe 關於 order res 解決方案:JsonResponse(data, json_dumps_params={‘ensure_ascii‘:False}) ! data是需要渲染的字典 def master
關於網站開發中div標簽中設置寬度後其中文本溢出的原因和解決方法
lan 解析 info tro 情況 href targe 圖片 com 一.問題產生的原因 當我們為div標簽聲明了寬度,但是仍然會出現文本越界的情況,不知道大家有沒有發現,只有文本內容為單詞或者純數字 的時候才會出現這種情況為此我特意測試了兩種情況,結果如下:
vue2.0 element-ui中el-upload的before-upload方法返回false時submit()不生效解決方法
tip child 是我 pre gre 調用 2.0 技術 lis 我要實現的功能是在上傳文件之前校驗是否表格中存在重復的數據,有的話,需要彈窗提示是否覆蓋,確認之後繼續上傳,取消之後,就不再上傳。 項目中用的element-ui是V1.4.3 <el-upload
EF Core 中DbContext不會跟蹤聚合方法和Join方法返回的結果
contex cor core 匿名類型 也不會 類型 eating count 此外 EF Core中: 如果調用Queryable.Count等聚合方法,不會導致DbContext跟蹤(track)任何實體。 此外調用Queryable.Join方法返回的匿名類