aspose file tools*
The moose likes JDBC and the fly likes date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "date format" Watch "date format" New topic
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
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

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
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

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
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

parse method takes String as an argument, but probably your code is passing a Date type reference to it.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

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
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: date format
 
Similar Threads
conversion of date
How to fetch Date Field from excel sheet in Java
How to determine Data Format while we are getting Data from Excel Sheet
Date Validation
How to convert String to Date