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...")
 
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
function StrToTime(const Time string):TclDateTime;
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
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 :
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;
   
   
You may use the current AM and PM value, or the literals 'AM', 'am', 'PM' and 'pm' before or after the time.<br>
  {
 
   
'''Example:'''<br>
   myTime = StrToTime('3PM');
  '''var'''
  myTime : TclDateTime;<br>
  '''begin'''<br>
   myTime := StrToTime('3PM');
   ShowMessage('3PM      = '+TimeToStr(mytime));
   ShowMessage('3PM      = '+TimeToStr(mytime));
   myTime := StrToTime('15');
   myTime = StrToTime('15');
   ShowMessage('15      = '+TimeToStr(mytime));
   ShowMessage('15      = '+TimeToStr(mytime));
   myTime := StrToTime('15:03');
   myTime = StrToTime('15:03');
   ShowMessage('15:03    = '+TimeToStr(mytime));
   ShowMessage('15:03    = '+TimeToStr(mytime));
   myTime := StrToTime('15:03:45');
   myTime = StrToTime('15:03:45');
   ShowMessage('15:03:45 = '+TimeToStr(mytime));<br>
   ShowMessage('15:03:45 = '+TimeToStr(mytime));
'''end;'''
}
</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>


'''Output:'''<br>
<h2> See Also </h2>
3PM      = 15:00:00
* [[System_Library#Type_Conversion_Functions | Type Conversion Functions]]
15      = 15:00:00
{{#seo:|title=StrToTime Using in Clomosy - Clomosy Docs}}
15:03    = 15:03:00
{{#seo:|description=Explore StrToTime on Clomosy! Learn how to convert string representations of time into date-time objects in your applications.}}
15:03:45 = 15:03:45

Latest revision as of 13:30, 24 December 2024

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:

See Also