I'm trying to format the current datetime and then save it to a database using hibernate. I got it to save using the default date format, i.e.:
Date date = new Date(); hibernateObject.setDate(date); hibernateObject.save(date); I've found a way to format it but it's really untidy and doesn't seem to work:
Date finalDate = null; try { Date date = new Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String sDate = df.format(date); finalDate = df.parse(sDate); } catch (ParseException pe) { System.out.println("ParserException while attempting to establish date"); } hibernateObject.setDate(date); hibernateObject.save(date);
DATETIME