I need to convert "2016-11-08T13:04:16.5260175Z" this one into DateTime format like "11/8/2016 1:04 PM". Please help me.
I think that the most reliable method is to use the JSON.deserialize method. This accounts for time zones etc and is invoked like this:
DateTime result = (DateTime)JSON.deserialize('"' + '2016-11-08T13:04:16.5260175Z' + '"', DateTime.class); System.debug(result);
Note that I've put an extra set of double quotes around the string you want to parse. JSON is going to expect those, and you'll get odd results without them.
string s = '2016-11-08T13:04:16.5260175Z'; s = s.substring(0,s.indexOf('.')); s= s.replace('T',' '); datetime d= datetime.valueof(s);