在python中怎么把当前时间写入DolphinDB流表
我在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中把当前系统时间写入流表,代码如下:
import dolphindb as ddbimport 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 ])
运行后,我查询得到的数据如下图所示:
这里有2个问题,一个问题是np.datetime64('now',"ms")得到的毫秒数不对,它总是000;另一个问题是np.datetime64('now')得到的是utc时间,不是localtime。请问要得到正确的时间应该怎么实现?
回答:
可用datetime模块中的datetime.now()得到当前时间,代码修改如下:
from datetime import datetimeimport 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(
datetime.now(),"ms"),np.datetime64(datetime.now()),0.01 ])
以上是 在python中怎么把当前时间写入DolphinDB流表 的全部内容, 来源链接: utcz.com/a/165930.html