2013-03-11 27 views
-1

我想要使用SimpleDateFormat但我總是有錯誤,我不知道爲什麼?在android上顯示json

這是我的代碼:

package com.mobiblanc.wydadnews.beans; 

import java.io.Serializable; 
import java.text.SimpleDateFormat; 

import android.net.ParseException; 

public class Article implements Serializable { 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 

    private String title; 
    private String excerpt; 
    private String content; 
    private String pubdate; 

    public String getDate() { 

     return pubdate; 

     SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 

     try { 


      this.pubdate=fmt.format(pubdate); 



     } catch (ParseException e) { 

      e.printStackTrace(); 

     } 

    } 


    public void setDate(String date) { 
     this.pubdate = date; 

    } 



    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    public String getExcerpt() { 
     return excerpt; 
    } 

    public void setExcerpt(String excerpt) { 
     this.excerpt = excerpt; 
    } 

    public String getContent() { 
     return content; 
    } 

    public void setContent(String content) { 
     this.content = content; 
    } 
} 
+6

什麼是錯誤?請分享logcat日誌.. – 2013-03-11 12:26:45

+0

請加錯,也請輸入。 – 2013-03-11 12:44:15

+0

你期望getDate()做什麼? (java101(實際上編程101):返回通常是在方法中執行的最後一條語句。) – njzk2 2013-03-11 12:56:42

回答

1

什麼,我看到的是,你的GETDATE()的方法始終在呼喚SimpleDateFormat的前返回日期。

public String getDate() { 

    return pubdate; // this returns date; remove it 

    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 

    try { 


     this.pubdate=fmt.format(pubdate); 



    } catch (ParseException e) { 

     e.printStackTrace(); 

    } 

} 
+0

高度關注2細節傢伙+1 – 2013-03-11 12:49:43

+0

是「return pubdate」;我做了一個錯誤它不會在那裏,我的代碼是這樣的 私人字符串標題; \t私人字符串摘錄; \t私人字符串內容; \t private String pubdate; \t @SuppressLint( 「SimpleDateFormat的」) \t \t \t公共字符串GETDATE(){\t \t \t SimpleDateFormat的FMT =新的SimpleDateFormat( 「YYYY-MM-DD HH:MM:SS.SS」) ; \t \t \t \t嘗試{ \t \t \t this.pubdate = fmt.format(pubdate的); \t \t}趕上(ParseException的發送){ \t \t \t // TODO自動生成的catch程序塊 \t \t \t e.printStackTrace(); \t \t} \t \t回報pubdate的; \t} – Sherlock 2013-03-11 14:02:31