Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert string to dateformat dd/MM/yyyy

Tags:

android

String date = '15/2/2014'
SimpleDateFormat simpleDate = new SimpleDateFormat("dd/MM/yyyy");
Date d = simpleDate.parse(date);

now Date d return : d= Sat Feb 15 00:00:00 MMT 2014.

I want to get this format d= '15/2/2014'

How can I do it?

like image 895
dragullar Avatar asked Feb 15 '14 04:02

dragullar


2 Answers

Try this:

String date="15/02/2014";
SimpleDateFormat dateFormat= new SimpleDateFormat("dd/MM/yyyy");

try {
  Date d=dateFormat.parse(date);
  System.out.println("DATE"+d);
  System.out.println("Formated"+dateFormat.format(d));
}
catch(Exception e) {
  //java.text.ParseException: Unparseable date: Geting error
  System.out.println("Excep"+e);
}

Hope this help.

like image 94
Jay Vyas Avatar answered Oct 01 '22 22:10

Jay Vyas


You can try like this: (Here you can change time variable with your input string)

String time = "Sun Jul 15 2012 12:22:00 GMT+03:00 (FLE Daylight Time)";
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss zzz");
Date date = sdf.parse(time);

SimpleDateFormat sdf=new SimpleDateFormat("dd/M/yyyy");
String s=sdf.format(date.getTime());
like image 33
Pratik Butani Avatar answered Oct 01 '22 20:10

Pratik Butani