1

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..

3 Answers 3

2

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 ;)

0
3

This sounds like SQL date format from ISO 9075:

YYYY-MM-DD HH:MM:SS

Apex Datetime.valueOfGmt(string) can inhale it:

Datetime midnight = Datetime.valueOfGmt('2015-07-27 00:00:00');

Then you can use Datetime.formatGmt(format) to output it:

midnight.formatGmt('MM/dd/yy'); //gives you "07/27/15"

Be careful with the GMT input and output to avoid moving off the exact date boundary. Manual formatting should be used sparingly; instead the running user's locale setting should be respected.

2

You can use DateTime.format method - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_datetime.htm#apex_System_Datetime_format_2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .