07-24-2009 08:23 AM
I need to convert the selected date from DateField to some string format (for example: yyyy-mm-dd).
I had set the DateField date format as "mm-dd-yyyy'.
I tried to get the date from that DateField and tried to convert it into "yyyy-mm-dd" format.
When I tried I got some wrong output.
For example, when I selected 12 as month it returned as "00" with the following coding.
SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-mm-dd"); Date dtToConvert = new Date(mydatefield.getDate()); strRequired = dtFormat.formatLocal(dtToConvert);
Can anyone explain what is the bug with this code or any other way to get the output as my requirement?
Thanks in advance,
Solved! Go to Solution.
07-24-2009 08:41 AM
This is code I have used in the past :
DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); long dateLong = field.getDate(); String dateString =df.format(dateLong);
That should give you thedate String you want.
07-24-2009 09:15 AM
Thanks for the reply.
I am using eclipse plugin for the development for Storm.
When I tried to use the date format as like you given it showing the error.
The method format(Object) in the type Format is not applicable for the arguments (long)
Can you tell whether it is correct code?
07-24-2009 10:06 AM
Oops, sorry, code should have been...
DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); long dateLong = field.getDate(); Date date = new Date(dateLong); String dateString =df.format(date);