OCLOperators tryParse
Charles Olet (talk | contribs) No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
The tryParse operator converts a string representation of a date and time to its DateTime equivalent. Null is returned if the string is | 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 | The string to be parsed can be in any of the following forms: | ||
* A string with a date and a time component. | * A string with a date and a time component. | ||
Line 69: | Line 69: | ||
|} | |} | ||
* A string that includes the GMT designator and conforms to the <nowiki>RFC 1123</nowiki> time format | * A string that includes the GMT designator and conforms to the <nowiki>RFC 1123</nowiki> time format - for example: "Sat, 01 Nov 2008 19:35:00 GMT" | ||
{| class="wikitable" | {| class="wikitable" | ||
!OCL | !OCL | ||
Line 78: | Line 78: | ||
|} | |} | ||
* A string that includes the date and time along with time zone offset information | * A string that includes the date and time along with time zone offset information - for example: "03/01/2009 05:42:00 -5:00" | ||
{| class="wikitable" | {| class="wikitable" |
Revision as of 05:20, 19 August 2024
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 |
This page was edited 57 days ago on 01/20/2025. What links here