Amazon

Sunday, May 31, 2015

HOW TO CONVERT STRING TO DATE IN SALESFORCE

THE FOLLOWING IMAGE SHOWS THE STRING FORMAT OF JAVASCRIPT

CONVERSION CODE IS HERE

Map <String, Integer> monthNames = new Map <String, Integer> {'Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12};

extendAppEnd = 'Sun May 31 2015 09:30:00 GMT+0000';

//split the string based on spaces first
List <String> stringParts = extendAppEnd.split(' ');

The list after spliting like the follow values

/*stringParts[0] = 'Sun'
stringParts[1] = 'May'
stringParts[2] = '31'
stringParts[3] = '2015'
stringParts[4] = '09:30:00'
stringParts[5] = 'GMT+0000' */

//and split the time string based on ( : ).
List <String> timeParts = stringParts[4].split(':');
he list after spliting like the follow values

/*timeParts [0] = 09
timeParts [1] = 30
timeParts [2] = 00*/


DateTime dt= DateTime.newInstanceGmt(Integer.valueOf(stringParts[3]), monthNames.get(stringParts[1]), Integer.valueOf(stringParts[2]), Integer.valueOf(timeParts[0]), Integer.valueOf(timeParts[1]), Integer.valueOf(timeParts[2]));

OUTPUT

2015,5,31,09,30,00



1 comment:

  1. Nice information. Salesforce is a most powerful CRM tool used for manage all customers including potential customers. Salesforce Course in Chennai offering this course with experienced professionals.

    ReplyDelete