timestamps in java sdk classes

Hello, I'm working with java sdk from few days and I'm trying to customize fit decode example to decode a fit file and get informations I need.

I've just notice that every timestamp values in recent fit files are referred to many years ago!!

For example, I've a fit file recorded this morning but every timestamps are referred to 2001!!!

I attach the fit file. Getting data from com.garmin.fit.SessionMesg, I see session timestamp = 985072705 (20/03/2001 08:18:25)

thank you in advance
179700444646.zip

  • The epoch for timestamps in the FIT SDK is 1989-12-31T00:00:00UTC. It looks like you are using the UNIX epoch. Or more than likely doing something like "new java.util.Date(985072705*1000)". There is a 631065600000 millisecond offset between the two epochs, or roughly 20 years. Which is the difference between what you expect and what you are seeing.

    The FIT DateTime class has the methods getTimestamp() and getDate(). The first returns the number of seconds since the FIT Epoch, and the latter returns a java.util.Date object with the offset applied. 

    You typically use the timestamp for calculating deltas between messages without the overhead of using java.util.Date objects, and java.util.Date when you need to display the absolute date.

    Also look in the Activity message for the local timestamp. The delta between the local time stamp and timestamp in the Activity message is the timezone offset.

    The Decoding FIT Activity Files recipe is written in C# , but the concepts are the same when working with the Java SDK. Both SDKs provide a similar API, so even how to use the SDK is very similar between both languages.

    https://developer.garmin.com/fit/cookbook/decoding-activity-files/