Hello good people, I need some little help about a confusion i'm having. since i came from C# .NET i was expeting java to have something similar to C# DateTime. While i manage to create a helper method to convert string representation of date like eg "2009-10-16 11:14:34" to date object. here is the method
public static Date convertToDateTime(String stringDate) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date;
try {
date = df.parse(stringDate);
} catch(ParseException e){
e.printStackTrace();
}
return date;
}
now i just want to persist now (i mean now date, like actual date) like New Date() and have that date in the database have the same representation yyyy-MM-dd HH:mm:s. Unless i'm not getting something fundamental
Since i'm using hibernate is it due to the mapping file? if so i have 2 question 1 How to then map my property so that New Date will be persited in this format yyyy-MM-dd HH:mm:s 2 How to have a default datetime mapping so if the property is null it still will be persited in the yyyy-MM-dd HH:mm:s format Thanks for reading