0

I am storing a date to database by converting util date to sql date by using following code

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");  
sdf.setLenient(false);
java.sql.Date dobSQLDate = null;
Date date = null;
if(!("").equals(userDob)){date = sdf.parse(userDob);dobSQLDate = new java.sql.Date(date.getTime());}

now I want to show this date on my page in the dd/mm/yyyy format in which it was taken... How do I convert this?

vikas devde
  • 11,691
  • 10
  • 35
  • 42

3 Answers3

1

you can use the format method on your SimpleDateFormat object. It takes a java.util.Date object and returns a String formatted based on the format string specified.

Peter Elliott
  • 3,273
  • 16
  • 30
0

you can use DateFormatUtils

//Formats you dateto a specific pattern
 DateFormatUtils.format(yourDate, "dd/MM/yyyy");
Kadiri
  • 288
  • 3
  • 9
0

Dates do not have a "format" that you can set - they are just an instant in time.

If you want to display a date in a certain format, you must render the date to a String using code such as:

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");  
String dateString = sdf.format(date);
Bohemian
  • 412,405
  • 93
  • 575
  • 722