+ Start a Discussion
sdfasdsdfasd 

how to convert the datetime field to salesforce datetime like 'yyyy-MM-dd\'T\'hh:mm:ss\'Z\''

how to convert the datetime field to salesforce datetime like 'yyyy-MM-dd\'T\'hh:mm:ss\'Z\''. this format i am write code like this.

       DateFormat BSD;

        DateFormat BSD = new SimpleDateFormat('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');                               
        BSD.setTimeZone(TimeZone.getTimeZone('GMT'));

 

 

i need  DateTime  yyyy-MM-dd\'T\'hh:mm:ss\'Z\''   this  formate pls help me.........

 

alok29novalok29nov

If your datetime format is like this : '2012-08-19T19:30:07:00Z'. Then you can try below code.

 

string dt1= '2012-08-19T19:30:07:00Z';
string dt2 = dt1.replace('T',' ');
string dt3 = dt2.replace('Z,' ');

 

Then datetime newdt  = datetime.valueof(dt3 );

 

Hope it helps!

Rahul SharmaRahul Sharma

Hi sdfasd,

 

If you want to convert a string 'yyyy-MM-dd\'T\'hh:mm:ss\'Z\'' to its equivalent date time then you would have to replace that to a valid DateTime String before converting it to datetime.

 

Run below query in system log to check if thats what you are looking for:

 

String strdate = '2012-01-08\'T\'07:49:04\'Z\''; //Date with quotes
strDate = strDate.replace('\'T\'', ' ').replace('\'Z\'', ''); //Replace the unnecessary string to make a datetime valid string
datetime dt = datetime.valueOf(strDate); //Convert string to equivalent date time
system.debug('==Converted Date=='+dt); //Print the converted date time value

 

Kumar Gaurav 4Kumar Gaurav 4
DateTime startDate = DateTime.Now();
String formatStr = 'yyyyMMdd\'T\'HHmm\'00\'';
str = startDate.format(formatStr);
system.debug(str);