gpt4 book ai didi

java - Hibernate:如何提取时间部分

转载 作者:行者123 更新时间:2023-12-01 14:37:21 24 4
gpt4 key购买 nike

只想使用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 方法时,它会显示日期。

有没有办法只显示时间部分......

最佳答案

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

关于java - Hibernate:如何提取时间部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16359603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com