This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date format

 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into DateFormat/SimpleDateFormat class.

 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Aditi, you need the following two

java.text.DateFormat
java.text.SimpleDateFormat
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
parse method takes String as an argument, but probably your code is passing a Date type reference to it.
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if that is the case, try the following once

 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you swastik its been solved i have just tried it once again & rectify my silly mistake

thank you
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic