2015-01-10 70 views
1

我試圖從Parse.com得到createdAt日期和讓它格式:「DD/MM/YYYY「,並把它放在一個textview中,但它不工作。如何從parse.com獲取日期並將其設置爲MM/DD/YYYY android系統

這是我寫的代碼:

dateCreatedText.setText(new SimpleDateFormat("DD/MM/YYYY").format(
       currentUser.getCreatedAt().getDay()+"/" 
       +currentUser.getCreatedAt().getMonth()+"/" 
       +currentUser.getCreatedAt().getYear())); 

這是我收到的錯誤:

01-10 18:41:55.018: E/AndroidRuntime(3314): Caused by: java.lang.IllegalArgumentException 
01-10 18:41:55.018: E/AndroidRuntime(3314):  at java.text.DateFormat.format(DateFormat.java:361) 
01-10 18:41:55.018: E/AndroidRuntime(3314):  at java.text.Format.format(Format.java:93) 

我怎樣才能讓它工作呢?

+0

錯誤說明了一切。 –

回答

2

你可以這樣做:

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); 
dateCreatedText.setText(formatter.format(currentUser.getCreatedAt())); 
+0

我試過了,我得到這個錯誤:未知模式字符'Y' – Michael

+0

@Michael編輯,它現在工作? – aluxian

+0

謝謝!它現在有效:D – Michael

相關問題