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!.
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!.
You can format with userinfo.getTimeZone();
DateTime dtNow = //any date here
String formattedDate = dtNow .format('yyyy-MM-dd', UserInfo.getTimeZone().toString());
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);
UserInfo.getTimeZone().toString()
.. updated answer pls check
Commented
Oct 11, 2016 at 12:07
Take a look at following link, hope it help. Date/Time Field - Independent of User Locale