Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

在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 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 ])

运行后,我查询得到的数据如下图所示:
image.png

这里有2个问题,一个问题是np.datetime64('now',"ms")得到的毫秒数不对,它总是000;另一个问题是np.datetime64('now')得到的是utc时间,不是localtime。请问要得到正确的时间应该怎么实现?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

可用datetime模块中的datetime.now()得到当前时间,代码修改如下:

from datetime import datetime
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(
datetime.now(),"ms"),np.datetime64(datetime.now()),0.01 ])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...