From Clomosy Docs

No edit summary
No edit summary
 
(3 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>
  myTime = StrToTime('3PM');
 
  ShowMessage('3PM      = '+TimeToStr(mytime));
'''Example:'''<br>
  myTime = StrToTime('15');
:'''Base Syntax'''
  ShowMessage('15      = '+TimeToStr(mytime));
  var
  myTime = StrToTime('15:03');
    myTime : TclDateTime;
  ShowMessage('15:03    = '+TimeToStr(mytime));
 
  myTime = StrToTime('15:03:45');
  begin
  ShowMessage('15:03:45 = '+TimeToStr(mytime));
 
    myTime := StrToTime('3PM');
}
    ShowMessage('3PM      = '+TimeToStr(mytime));
</pre>
    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));
 
  end;


:'''TRObject Syntax'''
<b>Output:</b><br>
  var
<div class="alert alert-success" role="alert" data-bs-theme="light">
    myTime : TclDateTime;
3PM      = 15:00:00<br>
 
15      = 15:00:00<br>
  {
15:03    = 15:03:00<br>
 
15:03:45 = 15:03:45
    myTime = StrToTime('3PM');
</div>
    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:'''<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