Reputation: 112
I’m trying to insert the current system time into a DolphinDB stream table from Python, but there are two issues with timestamps:
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 ])
How to get the correct time?
Upvotes: 0
Views: 32
Reputation: 142985
It may need to get time.time()
substract time.timezone
and multiply by 1_000 (10**3) to get milliseconds
np.datetime64( int((time.time()-time.timezone)*10**3), 'ms')
Previous answer. It is WRONG because locatime()
removes milliseconds, and it needs time.timezone
and I forgot *10**3
You can use time.localtime()
to get local time (with milliseconds), and use time.mktime()
to convert it to epoch
which you can use in datetime64()
np.datetime64(int(time.mktime(time.localtime())), 'ms')
Upvotes: 1