-1

我想有时间使用SimpleDateFormat,但我总是有错误,我不知道为什么?

这是我的代码:

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;
    }
}
4

1 回答 1

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(); 

    }

}
于 2013-03-11T12:45:51.667 回答