【问题标题】:How to convert CAN message TimeStamp in python Time to System time?如何将python时间中的CAN消息时间戳转换为系统时间?
【发布时间】:2019-05-31 10:28:00
【问题描述】:
import time 
import can

def ReceiveMsg():
    bus = can.interface.Bus(channel= '1', bustype='vector',app_name = 'python-can')
    while True:
            a_listener = can.Listener()
            Message = bus.recv()
            a_listener.on_message_received(Message)
            if (Message != None) & (Message.arbitration_id == 0x329):
                print('Message is :',Message)
                return Message

if __name__ == '__main__':
    ReceiveMsg()

如果我执行,我会得到下面的输出

Message is : Timestamp: 1559297416.090523        ID: 0329    S                DLC:  8    ca 00 03 28 00 00 00 00     Channel: 1

1559297416.090523 - 这是 Python 时间戳

在输出中 Timestamp: is given Python time

如何将 Python 时间转换为系统时间???

【问题讨论】:

  • 乘以 1000 能解决您的问题吗?

标签: python python-3.x python-can


【解决方案1】:

here的回答

Python 3:

from datetime import datetime, timezone
datetime.fromtimestamp(Message.timestamp)

Python 2 中,使用pytz

from datetime import datetime
import pytz
datetime.fromtimestamp(Message.timestamp, pytz.utc)

【讨论】:

    猜你喜欢
    • 2018-06-06
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 2013-02-08
    • 2019-02-03
    • 1970-01-01
    • 2019-10-30
    • 2019-10-07
    相关资源
    最近更新 更多