1.日期:
@Temporal(TemporalType.DATE)
@Column(name = "createDate", nullable = false, length = 10)
public Date getCreateDate() {
return createDate;
}
在页面端取值:2011-04-12
2.时间:
@Temporal(TemporalType.TIME)
在页面端取值:22:50:30
3.日期和时间(默认):
@Temporal(TemporalType.TIMESTAMP)
在页面端取值:2011-04-12 22:51:34.0
TemporalType类型,请看源码
/**
* Type used to indicate a specific mapping of <code>java.util.Date</code>
* or <code>java.util.Calendar</code>.
*
* @since Java Persistence 1.0
*/
public enum TemporalType {
/**
* Map as <code>java.sql.Date</code>
*/
DATE,
/**
* Map as <code>java.sql.Time</code>
*/
TIME,
/**
* Map as <code>java.sql.Timestamp</code>
*/
TIMESTAMP
@Temporal(TemporalType.DATE)
@Column(name = "createDate", nullable = false, length = 10)
public Date getCreateDate() {
return createDate;
}
在页面端取值:2011-04-12
2.时间:
@Temporal(TemporalType.TIME)
在页面端取值:22:50:30
3.日期和时间(默认):
@Temporal(TemporalType.TIMESTAMP)
在页面端取值:2011-04-12 22:51:34.0
TemporalType类型,请看源码
/**
* Type used to indicate a specific mapping of <code>java.util.Date</code>
* or <code>java.util.Calendar</code>.
*
* @since Java Persistence 1.0
*/
public enum TemporalType {
/**
* Map as <code>java.sql.Date</code>
*/
DATE,
/**
* Map as <code>java.sql.Time</code>
*/
TIME,
/**
* Map as <code>java.sql.Timestamp</code>
*/
TIMESTAMP
}
转载于http://dqywg.iteye.com/blog/1408188