0

只想使用hibernate在数据库中插入时间部分....

我正在尝试的是......

public static void main(String[] args)
{
    Calendar cal = Calendar.getInstance();
    UserID ui = new UserID();
    CompKeyClass ckc1=new CompKeyClass();
    ckc1.setAge(21);
    ckc1.setUserID(ui);
    ui.setDeptno("1002");
    ckc1.setCal1(cal.getTime());
            ......

@Id
private UserID userID;
@SequenceGenerator(name="myseqgen",sequenceName="employeehib")
@GeneratedValue(generator="myseqgen")
private char man='a';
@Temporal(TemporalType.TIMESTAMP)
private Date hireDate;
@Temporal(TemporalType.TIME)
private Date timedate;
@Temporal(TemporalType.DATE)
private Date datedate;
@Temporal(TemporalType.DATE)
private Date cal1;
@Temporal(TemporalType.TIME)

但是在这里,当我调用 getTime 方法时,它会显示日期。

有什么办法只显示时间部分....

4

1 回答 1

1
int hours = cal.get(Calendar.HOUR_OF_DAY);
int minutes = cal.get(Calendar.MINUTE);
int seconds = cal.get(Calendar.SECOND);

或者

SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss");
String time = dateFormatter.format(cal.getTime());
于 2013-05-03T13:58:27.633 回答