From Clomosy Docs
(Created page with " function StrToTime(const Time string):TclDateTime; The StrToTime function attempts to convert a time as a string Date into a TclDateTime value. The time string must adhere to the format of the LongTimeFormat value, and use the TimeSeparator character to separate the hour, minute and second values. The default format is hour:minute:second.milli-seconds, where : :The hour must be 0..23 :The minute must be 0..59 (optional) :The second must be 0..59 (optional) :The mil...") |
ClomosyAdmin (talk | contribs) No edit summary |
||
| (4 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert"> | |||
function StrToTime(const S: string):TclDateTime; | |||
</div> | |||
Converts a string to a TclDateTime value.<br> | |||
Call StrToTime to parse a string that specifies a time value. If S does not contain a valid time, StrToTime raises an EConvertError exception.<br> | |||
The time string must adhere to the format of the LongTimeFormat value, and use the TimeSeparator character to separate the hour, minute and second values. The default format is hour:minute:second.milli-seconds, where : | |||
:The hour must be 0..23 | :The hour must be 0..23 | ||
| Line 7: | Line 12: | ||
:The milli-secs must be 0..999 (optional) | :The milli-secs must be 0..999 (optional) | ||
<b>Example</b><br> | |||
<pre> | |||
var | |||
myTime : TclDateTime; | |||
{ | |||
myTime = StrToTime('3PM'); | |||
myTime | |||
ShowMessage('3PM = '+TimeToStr(mytime)); | ShowMessage('3PM = '+TimeToStr(mytime)); | ||
myTime | myTime = StrToTime('15'); | ||
ShowMessage('15 = '+TimeToStr(mytime)); | ShowMessage('15 = '+TimeToStr(mytime)); | ||
myTime | myTime = StrToTime('15:03'); | ||
ShowMessage('15:03 = '+TimeToStr(mytime)); | ShowMessage('15:03 = '+TimeToStr(mytime)); | ||
myTime | myTime = StrToTime('15:03:45'); | ||
ShowMessage('15:03:45 = '+TimeToStr(mytime));<br> | ShowMessage('15:03:45 = '+TimeToStr(mytime)); | ||
} | |||
</pre> | |||
<b>Output:</b><br> | |||
<div class="alert alert-success" role="alert" data-bs-theme="light"> | |||
3PM = 15:00:00<br> | |||
15 = 15:00:00<br> | |||
15:03 = 15:03:00<br> | |||
15:03:45 = 15:03:45 | |||
</div> | |||
<h2> See Also </h2> | |||
* [[System_Library#Type_Conversion_Functions | Type Conversion Functions]] | |||
{{#seo:|title=StrToTime Using in Clomosy - Clomosy Docs}} | |||
{{#seo:|description=Explore StrToTime on Clomosy! Learn how to convert string representations of time into date-time objects in your applications.}} | |||
Latest revision as of 13:30, 24 December 2024
function StrToTime(const S: string):TclDateTime;
Converts a string to a TclDateTime value.
Call StrToTime to parse a string that specifies a time value. If S does not contain a valid time, StrToTime raises an EConvertError exception.
The time string must adhere to the format of the LongTimeFormat value, and use the TimeSeparator character to separate the hour, minute and second values. The default format is hour:minute:second.milli-seconds, where :
- The hour must be 0..23
- The minute must be 0..59 (optional)
- The second must be 0..59 (optional)
- The milli-secs must be 0..999 (optional)
Example
var
myTime : TclDateTime;
{
myTime = StrToTime('3PM');
ShowMessage('3PM = '+TimeToStr(mytime));
myTime = StrToTime('15');
ShowMessage('15 = '+TimeToStr(mytime));
myTime = StrToTime('15:03');
ShowMessage('15:03 = '+TimeToStr(mytime));
myTime = StrToTime('15:03:45');
ShowMessage('15:03:45 = '+TimeToStr(mytime));
}
Output:
3PM = 15:00:00
15 = 15:00:00
15:03 = 15:03:00
15:03:45 = 15:03:45