Description
The StrToTime
method converts the string S, to a Date value. The resulting value has only the time portion. To convert a string to a Date value having both the date and time portions, use the StrToDateTime
method.
Declaration
Applies To
The method is applied to the following object:
Parameters
The method has the following parameter:
S
Specifies the string to be converted. The method recognizes the time if the string has the "hh:mm:ss" format. Leading zeros, as well as the seconds part can be omitted. Both the 24-hour and 12-hour formats are supported. To indicate that the string represents time in the 12-hour format, use "AM", "PM", "am" or "pm".
If the source string does not represent valid time, StrToTime
raises an exception.
Result Value
The value of the Date type to which the specified string has been converted.
Example
The code below demonstrates how you can convert strings to time types values.
JavaScript, JScript
{
Log.Message(aqConvert.StrToDateTime("03:12 PM"));
Log.Message(aqConvert.StrToDateTime("10:56:35 AM"));
}
// The routine produces the following output:
// 3:12:00 PM
// 10:56:35 AM
Python
def StringToTime():
Log.Message(aqConvert.StrToDateTime("03:12 PM"))
Log.Message(aqConvert.StrToDateTime("10:56:35 AM"))
# The routine produces the following output:
# 3:12:00 PM
# 10:56:35 AM
VBScript
Log.Message(aqConvert.StrToDateTime("03:12 PM"))
Log.Message(aqConvert.StrToDateTime("10:56:35 AM"))
End Sub
' The routine produces the following output:
' 3:12:00 PM
' 10:56:35 AM
DelphiScript
begin
Log.Message(aqConvert.StrToDateTime('03:12 PM'));
Log.Message(aqConvert.StrToDateTime('10:56:35 AM'));
end;
// The routine produces the following output:
// 3:12:00 PM
// 10:56:35 AM
C++Script, C#Script
{
Log["Message"](aqConvert["StrToDateTime"]("03:12 PM"));
Log["Message"](aqConvert["StrToDateTime"]("10:56:35 AM"));
}
// The routine produces the following output:
// 3:12:00 PM
// 10:56:35 AM
See Also
Working With Dates
DateTimeToStr Method
DateTimeToFormatStr Method
StrToDateTime Method
StrToDate Method