[SalesForce] Convert String DateTime to User Locale Date Time

My string format : 10/11/2016 01:00 AM

I want to convert this String to DateTime to support in every user's locale format

I tried Date.parse, Date.valueOf but am not getting expected value.

Any help is appreciable thanks!.

Best Answer

You can format with userinfo.getTimeZone();

DateTime dtNow = //any date here 

String formattedDate = dtNow .format('yyyy-MM-dd',  UserInfo.getTimeZone().toString());

Updates

Try below code snippet to convert the string to DateTime.

String val = '2015-12-01T12:44:00.000+0000'; 

DateTime date1 = (DateTime)Json.deserialize('"'+val+'"', DateTime.class);

System.debug(date1)  ---> 2015-12-01 12:44:00

String dateformat = 'yyyy-MM-dd HH:mm:ss:sssZ';
String abc = date1.format(dateformat,''+userinfo.getTimeZone().toString());
system.debug(abc);