cancel
Showing results for 
Search instead for 
Did you mean: 

Getting current Time in Specific Time Zone

SOLVED
Highlighted
New Contributor

Getting current Time in Specific Time Zone

I am trying to get current time using vbscript. Instead of the user/system time zone, I would like to get current CST time. How to get current time in some specific Time Zone using vbscript in TestComplete?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Staff

Re: Getting current Time in Specific Time Zone

no, not with aqdatetime.

if you can find a reliable, free API that gives you current time at a specified timezone, then you could use the aqHttp object and do a get request. 

then you'd most likely have to save the response body as a variable and then pull the proper key value pairs to output the time

Best,
Justin Kim

View solution in original post

Highlighted
Staff

Re: Getting current Time in Specific Time Zone

for example, using the free api at http://api.timezonedb.com, I created a free account to access the current time in Chicago, the below stub is in Python, but the methods used will be available in vbscript as well at https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqhttp/creategetrequest.ht...

 

 

 

        
def get_CST():
  
  address = "http://api.timezonedb.com/v2.1/get-time-zone?key=YOUR_API_KEY&format=json&by=zone&zone=America/Chicago"

  # Create an aqHttpRequest object
  aqHttpRequest = aqHttp.CreateGetRequest(address)

  # Send the request, get an aqHttpResponse object
  aqHttpResponse = aqHttpRequest.Send()

  if aqHttpResponse != None:
    # Read the response data
    Log.Message(aqHttpResponse.Text) # A response body
    
    df = aqHttpResponse.Text #in as a str
    date = df[-21:-2] #get daterange 
    Log.Message(date) #log a message of current CST date
    return date #output date
    
    
    # Save the response body to a file and place it to the project folder
    #aqHttpResponse.SaveToFile(Project.Path + "body.txt")

 

 

 

and the following logs of running this routine:

hkim5_0-1600446751935.png

 

 

Best,
Justin Kim

View solution in original post

5 REPLIES 5
Highlighted
Staff

Re: Getting current Time in Specific Time Zone

there is an aqDateTime object that can get the dates and times, but I'm not too sure if there are inbuilt methods to specify a timezone. Either way i think you could use something like aqDateTime.now to get the times, and then use aqDateTime.AddHours to add/subtract however many hours it would take to get to the desired time zone

Best,
Justin Kim
Highlighted
New Contributor

Re: Getting current Time in Specific Time Zone

Thank you.

 

We have employees in different Time Zones. But the desired result for Time zone is in CST. So subtracting and adding would not help. 

Is there a direct way to get current CST time?

Highlighted
Staff

Re: Getting current Time in Specific Time Zone

no, not with aqdatetime.

if you can find a reliable, free API that gives you current time at a specified timezone, then you could use the aqHttp object and do a get request. 

then you'd most likely have to save the response body as a variable and then pull the proper key value pairs to output the time

Best,
Justin Kim

View solution in original post

Highlighted
Community Hero

Re: Getting current Time in Specific Time Zone

Hi,

 

To add to what was suggested by @hkim5 :

You may look for some .Net or Java code and port it to your test using the dotNET or JavaClasses (Java Bridge) objects provided by TestComplete.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Staff

Re: Getting current Time in Specific Time Zone

for example, using the free api at http://api.timezonedb.com, I created a free account to access the current time in Chicago, the below stub is in Python, but the methods used will be available in vbscript as well at https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqhttp/creategetrequest.ht...

 

 

 

        
def get_CST():
  
  address = "http://api.timezonedb.com/v2.1/get-time-zone?key=YOUR_API_KEY&format=json&by=zone&zone=America/Chicago"

  # Create an aqHttpRequest object
  aqHttpRequest = aqHttp.CreateGetRequest(address)

  # Send the request, get an aqHttpResponse object
  aqHttpResponse = aqHttpRequest.Send()

  if aqHttpResponse != None:
    # Read the response data
    Log.Message(aqHttpResponse.Text) # A response body
    
    df = aqHttpResponse.Text #in as a str
    date = df[-21:-2] #get daterange 
    Log.Message(date) #log a message of current CST date
    return date #output date
    
    
    # Save the response body to a file and place it to the project folder
    #aqHttpResponse.SaveToFile(Project.Path + "body.txt")

 

 

 

and the following logs of running this routine:

hkim5_0-1600446751935.png

 

 

Best,
Justin Kim

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors