Type/to search
8
Follow
1375
Followers
2.12 _Función D() y marca de tiempo
Tutorials
Created 2016-12-29 16:28:35  Updated 2017-02-14 16:54:35
 2
 3602

_Función D() y marca de tiempo


  • JS horario

    Cuando se escribe una estrategia, es inevitable que se encuentre con el problema de usar el parche de tiempo, que en JS es un número de milisegundos.
    Por lo general no es muy intuitivo, se utiliza principalmente en el programa para juzgar el orden del tiempo, calcular la diferencia de tiempo, etc.
    Para ello, la plataforma tiene una función interna:_D() Función para mostrar la barra de tiempo como una cadena de caracteres.
    También hay ocasiones en las que se necesita convertir una descripción concreta en una columna de tiempo, ¿cómo se hace?

    Ejemplo de código:

    function main(){ // example TimeString to TimeStamp //timeStr format: "2016.12.01 13:55:60"; var stamp = new Date("2014-07-10 10:21:12:500").getTime(); Log("stamp:", stamp,"_D(stamp)" ,_D(stamp) ,"srting : 2014-07-10 10:21:12"); //timeStr format: "2016.12.01 13:55:60:300"; var stamp2 = new Date("2014-07-10 10:21:12").getTime(); Log("stamp2:", stamp2,"_D(stamp)" ,_D(stamp2) ,"srting : 2014-07-10 10:21:12"); var nowTimeStamp = new Date().getTime(); var nowTimeStr = _D(nowTimeStamp); Log(new Date(nowTimeStr).getTime(), nowTimeStamp); }

    El código de retroalimentación está funcionando:

    img

  • La barra de tiempo de Python

    Hay que tener en cuenta que la función _D() se usa de una manera un poco diferente en Python, y también lo probamos con el código.

    import time def main(): # example TimeString to TimeStamp # timeStr format: "2016.12.01 13:55:60"; # time.mktime(tupletime) # 接受时间元组并返回时间辍(1970纪元后经过的浮点秒数)。 stamp = time.mktime((2014, 7, 10, 10, 21, 12, 5, 0, 0)) Log("stamp:", stamp, "_D(stamp)", _D(stamp)," srting : 2014-07-10 10:21:12") stamp2 = time.mktime((2014, 7, 10, 10, 21, 12, 0, 0, 0)) Log("stamp2:", stamp2, "_D(stamp)", _D(stamp2), "srting : 2014-07-10 10:21:12") nowTimeStamp = time.time() nowTimeStr = _D(nowTimeStamp) Log("nowTimeStamp:", nowTimeStamp, "nowTimeStr:", nowTimeStr)

    Las pruebas retrospectivas muestran:

    img

Related Recommendations
Comment
All comments (2)

    _D() 在 python平台上的时间单位是秒,和说明里的不一样。所以k线数据里的Time需要除以1000

    10 years ago

    哦 ~是的 ,感谢提醒 ,我增加 对 python 的解释说明 ^^ , 不过 python 的策略中 使用 _D 传入 的参数 直接用 Python time.time() 返回的值就可以(秒级别的 时间戳),
    K线数据 中的时间戳是 毫秒级别的,需要在Python 策略中做 除以 1000 的转换,用于对比time.time() 返回的秒级时间戳。

    10 years ago
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)