我在数据库中有单独的日期和时间列,并且它们是根据我的 bean 映射的(使用休眠),我想保存格式化的(日期和时间),即分别为 2012 年 17 月 10 日和下午 2 点 47 分。我遇到了如何将格式化的日期和时间放入相应的列中的问题,因为我的数据库列设置为日期和时间类型,但格式化的日期和时间返回一个字符串。代码示例将非常有用。
DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy");
Date date = new Date();
salesOrder.setOrderDate(dateFormat.format(date));//Error:The method setOrderDate(Date) in the type SalesOrder is not applicable for the arguments (String)