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?
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.
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With