[Python] How to Insert Current Local Time with Millisecond Precision into DolphinDB Stream...

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to insert the current system time into a DolphinDB stream table from Python, but there are two issues with timestamps:

    1. Millisecond Precision Loss: When using np.datetime64('now', "ms"), the millisecond part is always 000 (e.g., 2023-10-01T12:34:56.000).
    2. UTC vs Local Time: np.datetime64('now') returns UTC time instead of local time.

    I have created the following stream table in DolphinDB databse:

    st=streamTable(
    array(LONG,0) as id,
    array(TIMESTAMP,0) as ts,
    array(DATETIME,0) as dt,
    array(DOUBLE,0) as value
    )
    share(st,"demoSt")


    python code:

    import dolphindb as ddb
    import numpy as np
    import pandas as pd

    s = ddb.session()
    c=s.connect("192.168.1.125", 8848, "admin", "123456")
    s.run("tableInsert{demoSt}", [1,np.datetime64('now',"ms"),np.datetime64('now'),0.01 ])


    output:[​IMG]

    How to get the correct time?

    Continue reading...

Compartilhe esta Página