You need to sign in to do that
Don't have an account?
Parse method in DateTime
Hi Guys,
I was trying to parse a specific format. its giving exception invalid Date/Time.Here the following is simple code.
Can any body help me on this issue.
DateTime dt = DateTime.now();
String str = dt.format('yyyy/MM/dd hh:mm:ss ');
dateTime mydate = dateTime.parse(str);
Error :
DEBUG LOG
20.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
Execute Anonymous: DateTime dt = DateTime.now();
Execute Anonymous: String str = dt.format('yyyy/MM/dd hh:mm:ss ');
Execute Anonymous: dateTime mydate = dateTime.parse(str);
19:52:19.039 (39170000)|EXECUTION_STARTED
19:52:19.039 (39217000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
19:52:19.040 (40663000)|EXCEPTION_THROWN|[3]|System.TypeException: Invalid date/time: 2011/08/29 07:52:19
19:52:19.040 (40947000)|FATAL_ERROR|System.TypeException: Invalid date/time: 2011/08/29 07:52:19
The following code works for me:
Note that we need the format as MM/dd/yyyy and it didnt accept seconds for some reason.
May be someone can shed light on the seconds part.