+ Start a Discussion
Rajesh SFDCRajesh SFDC 

how to convert date format in apex

here my input like this given below ;
1.string d1=27/11/2014 14:23:16

2.string d2=11/27/2014 14:23:16

3.strind d3=2014/11/27 14:23:16

4.string d4=2014/27/11 14:23:16
i need a like this output please help me any
Output
=============================================
final output like this : 11/27/2014 9:06 AM
rajesh k 10rajesh k 10
Hi,
   Go through below link
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000ApRJIA0
Kiran Kumar GottulaKiran Kumar Gottula
@Rajesh,

Debug the below 2 lines in developer console, I hope you get results.

DateTime Dt = DateTime.newInstance(2014, 6, 6, 14, 23, 16);
system.debug('========Dt=='+Dt.format());

Results:  15:13:33:048 USER_DEBUG [4]|DEBUG|========Dt==6/6/2014 2:23 PM

FYI: 

 See the Datetime methods in salesforce.
format()Converts the date to the local time zone and returns the converted date as a formatted string using the locale of the context user. If the time zone cannot be determined, GMT is used.Signature

public String format()

Return Value

Type: String

ExampleDateTime myDateTime = DateTime.newInstance(1993, 6, 6, 3, 3, 3); system.assertEquals('6/6/1993 3:03 AM', mydatetime.format());