0

I need to obtain Epoch time from a string (received from GPS) to set my RTC. From GPS I have a string like:

*timeString= 122347,other stuff,other stuff. ., other stuff.... where 12=hh, 23=mm, 47=ss

I need to convert these time numbers to standard epoch time i.e.

epochTime =1583504713;

How can I do that? (I know that to obtain correctly Unix time I need month,year and day too; I have alrady all theese information saved in int variables). Thanks all ;)

Dave

David
  • 9
  • 1
  • 1
    You can't convert hours to epoch, that does not make sense... How do you know which day is it? Gps time is composed of week number and time in the week. I guess you are receiving GGA, don't use it, use RMC – KamilCuk Mar 06 '20 at 14:38
  • You probably want to look into `timegm()` or `mktime()`. Fill a `struct tm` with the values and call one of these functions to get your unix timestamp. – Ctx Mar 06 '20 at 14:43
  • @Ctx You can, but I think the result will be inaccurate. Because UTC leap seconds. GPS time does not take leap seconds into account (and it recently overrun) . – KamilCuk Mar 06 '20 at 14:54
  • @KamilCuk What makes you think that these are not taken into account? – Ctx Mar 06 '20 at 14:55
  • @KamilCuk GPS time does not and unix timestamps do not, looks like we have a match here – Ctx Mar 06 '20 at 15:22
  • @KamilCuk: I think you are confusing the two timestamps: gps-time takes into account leap seconds (so one must have an updated table to convert to wall calendar), unix timestamps no (so constant number of second per year). – Giacomo Catenazzi Mar 12 '20 at 13:31

0 Answers0