-1

I have a Date 2014-10-01 00:00:00.0 I have to convert into 10/01.2014 How can i?

Rajesh
  • 23
  • 1
  • 1
  • 2

5 Answers5

6

how about this one

try
 {
    String currentDate = "2014-10-01 00:00:00.0";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
    Date tempDate=simpleDateFormat.parse(currentDate);
    SimpleDateFormat outputDateFormat = new SimpleDateFormat("dd/MM.YYYY");           
    System.out.println("Output date is = "+outputDateFormat.format(tempDate));
  } catch (ParseException ex) 
  {
        System.out.println("Parse Exception");
  }
Nurdin
  • 22,198
  • 39
  • 124
  • 293
2

Use SimpleDateFormat:

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format("Your date");
Paresh Mayani
  • 125,853
  • 70
  • 238
  • 294
Shriram
  • 4,244
  • 8
  • 30
  • 62
0

try This

// Create an instance of SimpleDateFormat used for formatting 
  // the string representation of date (month/day/year)
  DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

 // Get the date today using Calendar object.
   Date today = Calendar.getInstance().getTime();        
    // Using DateFormat format method we can create a string 
  // representation of a date with the defined format.
  String reportDate = df.format(today);

   // Print what date is today!
System.out.println("Report Date: " + reportDate);
Ravi Godara
  • 497
  • 6
  • 20
0

It's pretty easy if you use the JodaTime library.

    DateTime dt = new DateTime();
    DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd.YYYY");
    String str = fmt.print(dt);
mtbomb
  • 1,087
  • 1
  • 13
  • 16
0

try this:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date d = sdf.parse("dd/MM.YYYY");
Salah
  • 8,304
  • 3
  • 24
  • 41