[SalesForce] Convert String DateTime to User local DateTime

I need to convert the string datetime into user locale date time format.

for Ex:

//Consider this is Indian Time 22nd Dec 5 PM
String dateTime = '12-22-2016 17:00:00'; 

I want to convert this as per user locale. For ex, if the user is in United States, then I need to show the locale time as per the above given string datetime like below,

String dateTime = '12-22-2016 17:00:00';

then, If I need to show for America/los_angels timezone user locale,

//which is locale time for above datetime
datetimefield__c convertedDate = 12/22/2016 3:30 AM 

Best Answer

You can use DateTime methods to convert the time to user's Timezone.

String strDt = DateTime.now().format('MM/dd/yyyy HH:mm:ss', 'America/Los_Angels');