how to convert a timestamp_t to a real time?

给你一囗甜甜゛ 提交于 2020-01-04 09:37:33

问题


ive seen so many examples using a time_t, but timestamp_t is baffling me... Im doing an assignment where we need to print out GPS data, and the gps device returns a type timestamp_t for its time stamp and its an epoch time. Ive tried using gmtime() to convert and strftime() but nothing is working on that type. It keeps telling me it cannot convert timestamp_t* to time_t if i try using them.

Anyone know of any function that can convert a timestamp_t to human readable time?

thanks


回答1:


This site enter link description here Indicates it is a unix timestamp with a fractional part. Assuming this means the numbers to the left of the decimal are the number of seconds since 1/1/1970 and the 'decimal' component is a fractional part of one second, you could strip off the the integer component and use ctime():

time_t seconds;
timestamp_t ts = 1415000462.999000;

seconds = (time_t) timestamp_t;

printf("Time: %s\n", ctime(&seconds));

This of course ignores the fractional part of a second, but you should be able to handle that easily.



来源:https://stackoverflow.com/questions/26709107/how-to-convert-a-timestamp-t-to-a-real-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!