Pergunta

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

Foi útil?

Solução

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");
  }

Outras dicas

Use SimpleDateFormat:

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format("Your date");

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);

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);

try this:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date d = sdf.parse("dd/MM.YYYY");
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top