MyEclipse 中自定义日期格式

从数据库中读出Data数据:

而想实现的是这样:

 

解决办法:

1. 在这个类里添加自定义的变量birthf:

public abstract class AbstractUsers implements java.io.Serializable {

                   …… ;

                   private String birthf;

}

2. 在各个构造函数中添加:

public AbstractUsers(…… , String birthf) {

             …… ;
             this.birthf = birthf;
}

 

3. 生成get,set函数,再在get函数里添加代码:

public String getBirthf() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
Date date = (Date) this.getBirth();
birthf = sdf.format(date);
return birthf;
}

 

4. 在Users类里各构造函数里添加:

public class Users extends AbstractUsers implements java.io.Serializable {

public Users(……, String birthf) {
super(……,birthf);
}

}

 

5. 在.jsp中添加:

<li><span>出生日期:</span><%=user.getBirthf() %></li>

 

 

posted @ 2013-11-30 17:27  紫清婷  阅读(697)  评论(0编辑  收藏  举报