OCLOperators tryParse

The tryParse operator converts a string representation of a date and time to its DateTime equivalent. Null is returned if the string is not a valid date and or time.

The string to be parsed can be in any of the following forms,

  • A string with a date and a time component.
OCL Result
'08/18/2018 07:22:16'.tryParse('') 18/08/2018 07:22:16
  • A string with a date but no time component. If the time component is absent, the method assumes 12:00 midnight. If the date component has a two-digit year, it is converted to a year based on the Calendar.
  • A string with a date component that includes only the month and the year but no day component. The method assumes the first day of the month.
  • A string with a date component that includes only the month and the day but no year component. The method assumes the current year.
  • A string with a time but no date component.
  • A string with a time component that includes only the hour and an AM/PM designator, with no date component. The method assumes the current date and a time with no minutes and no seconds.
  • A string that includes time zone information and conforms to ISO 8601. In the following examples, the first string designates Coordinated Universal Time (UTC), and the second designates the time in a time zone that's seven hours earlier than UTC: "2008-11-01T19:35:00.0000000Z" "2008-11-01T19:35:00.0000000-07:00"
  • A string that includes the GMT designator and conforms to the RFC 1123 time format; for example: "Sat, 01 Nov 2008 19:35:00 GMT"
  • A string that includes the date and time along with time zone offset information; for example: "03/01/2009 05:42:00 -5:00"
This page was edited 32 days ago on 08/19/2024. What links here