function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
karthikeya 2karthikeya 2 

String to DateTime conversion ?

Hi all.

i am getting the time formate as "2016-03-03T01:09:36.933" from external system, its EST time.
i need to convert as local time.

ex: MM/DD/YYYY HH:MM

note time should be exactly shown in the formate no changes like Zeros should come.

Thanks in Advance.
sandeep@Salesforcesandeep@Salesforce
There are many DateTime method available as below:

format()
Converts the date to the local time zone and returns the converted date as a formatted string using the locale of the context user. If the time zone cannot be determined, GMT is used.
format(dateFormatString)
Converts the date to the local time zone and returns the converted date as a string using the supplied Java simple date format. If the time zone cannot be determined, GMT is used.
format(dateFormatString, timezone)
Converts the date to the specified time zone and returns the converted date as a string using the supplied Java simple date format. If the supplied time zone is not in the correct format, GMT is used.
formatGmt(dateFormatString)
Returns a Datetime as a string using the supplied Java simple date format and the GMT time zone.

These mgith be helpful.
https://developer.salesforce.com/docs/atlas.en-us.200.0.apexcode.meta/apexcode/apex_methods_system_datetime.htm#apex_System_Datetime_formatGmt

Thanks
Sandeep Singhal
Alexander TsitsuraAlexander Tsitsura
Hello,

For it, you can use JSON.deserialize method
 
DateTime dt = (DateTime) JSON.deserialize('"2016-03-03T01:09:36.933"', DateTime.class);
System.debug(dt); // 2016-03-03 06:09:36
System.debug(dt.format('MM/dd/yyyy HH:mm')); // 03/03/2016 01:09

If your question is answered, please mark a Best Answer. If you need more help, please add more details.

Thanks,
Alex
karthikeya 2karthikeya 2
No its not coming
and i need AM/PM after the date also
Ankit Gupta SFDCLearnerAnkit Gupta SFDCLearner
Do Simple. If you are getting date or datetime on your controller by actionfunction or actionsupport and your actionfunction or actionsupport is calling under <apex:inputfield>.

use below code:

String sDate = String.ValueOf('DATEGETBYACTIONSUPPORT or DATEGETBYACTIONFUNCTION');

System.Debug('sDate: ' + sDate);