Reputation: 8146
I want to parse date from string received from Textbox but some portion of value doesn't parsed and gave me some default values and store in my DB :
In my DB I have taken field type Timestamp without time zone in postgresql.
Following is my code :
Timestamp ts= null;
SimpleDateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy");
Date convertedDate = dateFormat.parse(command.getHolidayDate());
System.out.println("Date ::" + convertedDate);
System.out.println("T :: "+convertedDate.getTime());
System.out.println("Received :: "+command.getHolidayDate());
ts = new Timestamp(convertedDate.getTime());
entity.setHolidayDate(ts);
here entity.setHolidayDate store received date to DB.
System.our.println result :
Date ::Wed Jan 09 00:08:00 IST 2013
T :: 1357670280000
Received :: 08/09/2013
I am entering following date to textbox :
08/09/2013
In my DB table it stores as :
2013-01-09 00:08:00
why it's save data like this I don't have any idea. and one problem is that it's taking some random time as well that also I don't want. Any suggestion on this. Help.
Upvotes: 0
Views: 56
Reputation: 347204
I think you have an issue with your SimpleDateFormat
format...
mm
is "Minute in hour", not the month.
So looking at 2013-01-09 00:08:00
, you can see that that 08
represents the hour.
We would assume that you want to be getting 2013-08-09 00:00:00
, which means you should be using a format of MM/dd/yyyy
instead
Check out SimpleDateFormat
for more details
Upvotes: 3