+ Start a Discussion
Guru RamGuru Ram 

change date format mm/dd/yyyy to dd/mm/yyyy in apex class

Akshay_DhimanAkshay_Dhiman
Hi Guru,
Here is the piece of code that will help you convert your date "mm/dd/yyyy" to "dd-MM-yyyy" format in apex class.
DateTime yourDate = Datetime.now();
String dateOutput = yourDate.format('dd-MM-yyyy');
System.debug('Debug: '+dateOutput);
Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_date.htm
I hope it will you.
Regards,
Akshay
Nguyen TranNguyen Tran
The OP asked for Date format, not DateTime. My suggestion is convert Date to DateTime and then use format(stringFormat) from DateTime.