[SalesForce] Need to convert date format in apex

i want to convert

2015-07-27 00:00:00

into

mm/dd/yyyy

format in salesforce(Apex).

i have search the net do not get any proper way.pls help.

Thanks..

Best Answer

You could try extracting the date part in a String variable and then create a new instance of Date with your format.

String ExtractedDate = '2015-07-27';

list<String> lstSplitDate = ExtractedDate.split('-');
Date myDate = date.newinstance(Integer.valueOf(lstSplitDate[0]), Integer.valueOf(lstSplitDate[1]), Integer.valueOf(lstSplitDate[2]));

Home this will help you ;)