Get dates from AUT?

◇◆丶佛笑我妖孽 提交于 2019-12-01 12:41:33

Not sure about QTP, but the windows scripting host handles it via SetLocale

Option Explicit

Dim originalLocale
    originalLocale = GetLocale()

Dim aLocales
    aLocales = Array("en-us", "es-es", "de")

Dim locale, aDates, d

    For Each locale in aLocales
        WScript.Echo locale
        SetLocale locale

        aDates = Array( Date(), DateValue("01/02/2015"))
        For Each d in aDates
            WScript.Echo FormatDateTime(d, 1)
            WScript.Echo FormatDateTime(d, 2)
        Next 
        WScript.Echo "-------------------------------------------------"
    Next

    SetLocale originalLocale

While it is said (by Microsoft, see https://technet.microsoft.com/en-us/library/ee176965.aspx) that GetLocale and SetLocale are usable only in WebPages, those functions are exactly what I was looking for. And they work within QTP.

To convert a date value from the AUT (being a string) to a VBScript date value, I

  • call GetLocale to fetch and save the original locale
  • call SetLocale to switch to the same locale as the browser´s (read from registry)
  • use DateValue to convert the string to a native date (or use any other locale-sensitive routine)
  • call SetLocale with the original setting to switch back to the original locale.

Interestingly, QTP always starts a test´s execution with the system locale active -- even if the last test execution did leave behind a different locale set active.

See f.e. https://support.microsoft.com/de-de/kb/232158/en-us

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!