aqConvert.StrToTime Method

Applies to TestComplete 14.0, last modified on January 23, 2019

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

aqConvert.StrToTime(S)

S [in]    Required    String    
Result Date/Time

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

function 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

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

Sub StringToTime
  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

procedure StringToTime();
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

function 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

See Also

Working With Dates
aqConvert.DateTimeToStr Method
aqConvert.DateTimeToFormatStr Method
aqConvert.StrToDateTime Method
aqConvert.StrToDate Method

Highlight search results