| Author |
date format
|
Aditi agarwal
Ranch Hand
Joined: Feb 23, 2011
Posts: 225
|
|
i have a date field in my database in format (yyyy-mm-dd)
i want to convert it into following format
(dd-mm-yyyy)
please help me
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1196
|
|
Look into DateFormat/SimpleDateFormat class.
|
Swastik
|
 |
Aditi agarwal
Ranch Hand
Joined: Feb 23, 2011
Posts: 225
|
|
thanks swstik for your reply but do we need to import any class in our page for this because its showing error that
DateFormat & SimpleDateFormat cannot be resolved
please help
thank you
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1196
|
|
Yes Aditi, you need the following two
java.text.DateFormat
java.text.SimpleDateFormat
|
 |
Aditi agarwal
Ranch Hand
Joined: Feb 23, 2011
Posts: 225
|
|
The method parse(String) in the type DateFormat is not applicable for the arguments (Date)
this problem arises at word parse
please help
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1196
|
|
|
parse method takes String as an argument, but probably your code is passing a Date type reference to it.
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1196
|
|
And if that is the case, try the following once
|
 |
Aditi agarwal
Ranch Hand
Joined: Feb 23, 2011
Posts: 225
|
|
thats only what we have used its not a new one
please tell me any difference in 1st & 2nd code you posted
thank you
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1196
|
|
In the first case a String which is in yyyy-mm-dd format, is first converted to Date object using the parse method, and then that Date object is formatted as String dd-mm-yyyy format using format method.
In the later case you already have a Date object, that is just formatted to the required format using format method.
|
 |
Aditi agarwal
Ranch Hand
Joined: Feb 23, 2011
Posts: 225
|
|
hey swastik i have used the following code
but still my date is in yyyy-mm-dd format no change please help
|
 |
Aditi agarwal
Ranch Hand
Joined: Feb 23, 2011
Posts: 225
|
|
thank you swastik its been solved i have just tried it once again & rectify my silly mistake
thank you
|
 |
 |
|
|
subject: date format
|
|
|