# Time\_boot\_ms to real time?

**URL:** <https://discuss.bluerobotics.com/t/time-boot-ms-to-real-time/5740>\
**Category:** General Discussion\
**Tags:** ardusub, pymavlink\
**Created:** [August 9, 2019, 10:30pm UTC](https://discuss.bluerobotics.com/t/time-boot-ms-to-real-time/5740 "2019-08-09T22:30:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pyrov](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@pyrov](https://discuss.bluerobotics.com/u/pyrov)\
**Post date:** [August 9, 2019, 10:30pm UTC](https://discuss.bluerobotics.com/t/time-boot-ms-to-real-time/5740/1 "2019-08-09T22:30:31Z")

</div>

Hello,  
I have a question about this time\_boot\_ms value.  
I retrieve the realtime rov location with : recv\_match(type=‘GLOBAL\_POSITION\_INT’) and the time stamp it has is the ‘time\_boot\_ms’. I am wondering how I can relate this time to the real time accurately?

thanks.

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [August 12, 2019, 2:00pm UTC](https://discuss.bluerobotics.com/t/time-boot-ms-to-real-time/5740/2 "2019-08-12T14:00:41Z")

</div>

Hello,

All Mavlink2 messages have a [timestamp](https://mavlink.io/en/guide/message_signing.html#timestamps) in the header  
Try this:

```auto
import time
from datetime import datetime
from pymavlink import mavutil

master = mavutil.mavlink_connection('udpin:0.0.0.0:14550')

while True:
    try:
        message = master.recv_match()
        print(datetime.utcfromtimestamp(message._timestamp).strftime('%Y-%m-%d %H:%M:%S.%f'))
    except:
        pass
    time.sleep(0.1)

```

---

<div class="post-metadata">

**Author:** ![pyrov](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@pyrov](https://discuss.bluerobotics.com/u/pyrov)\
**Post date:** [August 13, 2019, 5:38pm UTC](https://discuss.bluerobotics.com/t/time-boot-ms-to-real-time/5740/3 "2019-08-13T17:38:48Z")

</div>

Willian, Thanks!  
I was able to use your code to get the DateTime output (I use the /dev/ttyACM0 connection as i am running on the raspberry pi).

Two follow up questions here:

1. Why the time output I got is like 2019-06-12 xx:xx:xx.xxxx. What could be the reason for the time shift?
2. How to link those DateTime output to the real-time ROV position output I got from:  
master.recv\_match(type=‘GLOBAL\_POSITION\_INT’).to\_dict()  
Thanks!

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [August 13, 2019, 6:39pm UTC](https://discuss.bluerobotics.com/t/time-boot-ms-to-real-time/5740/4 "2019-08-13T18:39:16Z")

</div>

That is odd, maybe that timestamp is from the raspberry pi, which only updates date and time when it is online.

Try checking the “SYSTEM\_TIME” messages

---

<div class="post-metadata">

**Author:** ![pyrov](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@pyrov](https://discuss.bluerobotics.com/u/pyrov)\
**Post date:** [August 13, 2019, 7:01pm UTC](https://discuss.bluerobotics.com/t/time-boot-ms-to-real-time/5740/5 "2019-08-13T19:01:51Z")

</div>

That’s right. The timestamp message returned the local machine time (which is 6/12 now).

Do I use  
print(datetime.utcfromtimestamp(message.\_SYSTEM\_TIME).strftime(‘%Y-%m-%d %H:%M:%S.%f’))

?

How about the 2nd question?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [August 13, 2019, 9:07pm UTC](https://discuss.bluerobotics.com/t/time-boot-ms-to-real-time/5740/6 "2019-08-13T21:07:29Z")

</div>

SYSTEM\_TIME is a mavlink message, so you should use `master.recv_match(type=‘SYSYEM_TIME’).to_dict()`

For the [SYSTEM\_TIME](https://mavlink.io/en/messages/common.html#SYSTEM_TIME) message, I think the best way is to read the first SYSTEM\_TIME and store both the time reported by it and time\_boot\_ms. With this you can calculate when the Pixhawk booted (let’s call it base\_time) and then, to get the real time from a message you can just do base\_time + time\_boot\_ms.
