OCLOperators tryParse
m ((username removed) (log details removed)) |
(Added Edited template with July 12, 2025.) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Edited|July|12|2025}} | |||
The tryParse operator converts a string representation of a date and time to its DateTime equivalent. Null is returned if the string is an invalid date and/or time. | The tryParse operator converts a string representation of a date and time to its DateTime equivalent. Null is returned if the string is an invalid date and/or time. | ||
Line 87: | Line 88: | ||
|8/18/2018 3:22:16 PM | |8/18/2018 3:22:16 PM | ||
|} | |} | ||
[[Category:OCL String Operators]] |
Latest revision as of 06:33, 20 January 2025
This page was created by Charles on 2024-08-16. Last edited by Edgar on 2025-01-20.
The tryParse operator converts a string representation of a date and time to its DateTime equivalent. Null is returned if the string is an invalid 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('') | 8/18/2018 07:22:16 AM |
- 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.
OCL | Result |
---|---|
'08/18/2018'.tryParse('') | 8/18/2018 12:00:00 AM |
- 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.
OCL | Result |
---|---|
'8/2018'.tryParse('') | 8/1/2018 12:00:00 AM |
- A string with a date component that includes only the month and the day but no year component. The method assumes the current year.
OCL | Result |
---|---|
'8/18'.tryParse('') | 8/18/2024 12:00:00 AM |
- A string with a time but no date component. The method assumes the current date.
OCL | Result |
---|---|
'07:22:16'.tryParse('') | 8/18/2024 7:22:16 AM |
- 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.
OCL | Result |
---|---|
'7 PM'.tryParse('') | 8/18/2024 7:00:00 PM |
- 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"
OCL | Result |
---|---|
'2018-08-18T07:22:16.0000000Z'.tryParse('') | 8/18/2018 10:22: 16 AM |
'2018-08-18T07:22:16.0000000-07:00'.tryParse('') | 8/18/2018 5:22:16 PM |
- 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"
OCL | Result |
---|---|
'Sat, 18 Aug 2018 07:22:16 GMT'.tryParse('') | 8/18/2018 10:22:16 AM |
- A string that includes the date and time along with time zone offset information - for example: "03/01/2009 05:42:00 -5:00"
OCL | Result |
---|---|
'08/18/2018 07:22:16 -5:00'.tryParse('') | 8/18/2018 3:22:16 PM |