Below is the code i used for conversion...
Out put is New Date: Mon Jul 16 13:45:12 IST 2012
But i need date format to be dd-MM-yyyy with time stamp and that date should of Date datatype.
Cab any body help me please.
Note that format() method will return only String representation and you already have a Date object created using the parse() method.
This is what happened when I copied your code
You ought not to use new Date(int, int, int).
[campbell@xxx java]$ javac DateEx.java
Note: DateEx.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[campbell@campbell-inspiron1110 rubbish]$ java DateEx
New Date: Sat Mar 01 00:00:00 GMT 3913
You need to check how you are setting your date, and why I am getting 1sr March 3913 from exactly the same code you posted.
Really its working if we use Calendar.
The problem in Date is that some methods are deprecated. Finally i got the solutions by your suggestions.
Here the main thing that, we are fetching two dates (lets say dtInstr and newDate) from back-end(data base). Based on dtInstr we have to genarate newDate.
This new from back end will be 15 days after dtInstr. This calculation made at backend only.
At front end we have to handle as below
if day of dtInstr =16 then newDate = 01/ next month of month dtInstr / year
else if day of dtInstr =23 then newDate = 08/ next month of month dtInstr / year
else newDate = newDate from back end
in 16 and 23 dates, we have to hard code the new date as string and convert into Date because we already have DVO which contains getters and setters method of date.
Campbell Ritchie wrote:There is nothing new about my suggestion; it is a standard principle to avoid number literals.
Marc Heruela wrote: . . . haha.. good one..
Especially since the month numbers to be used with java.util.Calendar are 0-based instead of 1-based, which is very confusing.
So, January = 0, February = 1, ..., July = 6, ... December = 11 instead of the normal numbers 1 - 12 that we are used to.
If you use Calendar.JULY instead of the plain numbers, it's much clearer which month you mean.