2011-11-16 112 views

回答

1
@user.birthday.strftime "%A, %B %d,%Y" 
+0

像魅力一樣工作。謝謝!! – absolutskyy

2

它不正確的格式顯示出來的原因是,Rails的視圖並在必要時調用to_s

你應該Internationalization and Localization of Rails做到這一點。

所以在你的例子中,I18n.l @user.birthday應該做的伎倆。您應該檢查您的語言環境的默認日期格式是什麼,它位於`config/locales/.yml。您可以按照"How to store custom translations"中的說明添加您的格式。因此,通過增加

en: 
    date: 
    formats: 
     default: "%A, %B %d,%Y" 

這種格式將用於在任何你約會調用I18n.l

0

試試這個<model>.created_at.to_date.to_s(:long)

相關問題