I have a function that needs to return a Date, I have a Date String of
'2016-02-09T12:22:00.000+00:00'
and want to convert it to
'2016-02-09 12:22:00'
but my return result is a string, in my case i want this to be a date. Here is my function so far i have tried is:
private Date parse(String s){ // function needs to return date as yyyy-mm-dd HH:mm:ss
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
SimpleDateFormat output = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d = null;
try {
d = sdf.parse(s);
} catch (ParseException e) {
e.printStackTrace();
}
String formattedTime = output.format(d);
System.out.println("Formated Date is = "+ formattedTime); // return date in yyyy-mm-dd HH:mm:ss (but a string)
return date; (Here i want the expected date to be as yyyy-mm-dd HH:mm:ss, I am getting as 'Tue Feb 09 12:22:00 GMT+05:30 2016')
}
Please help me its been a while trying this and am failing every time.
Thanks.