Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extensions for GPS time
namespace System
{
public static class GpsTime
{
public static int ToGpsTimeWeekNumber(this DateTime datetime)
{
DateTime datum = new DateTime(1980, 1, 6, 0, 0, 0);
TimeSpan difference = datetime.Subtract(datum);
return (int)(difference.TotalDays / 7);
}
public static int ToGpsTimeSeconds(this DateTime datetime)
{
DateTime datum = new DateTime(1980, 1, 6, 0, 0, 0);
DateTime secondsdiff = datetime.AddDays(datetime.ToGpsTimeWeekNumber() * -7);
TimeSpan difference = secondsdiff.Subtract(datum);
return (int)difference.TotalSeconds;
}
public static DateTime FromGpsTime(int weeknumber, int seconds)
{
return new DateTime(1980, 1, 6, 0, 0, 0).AddDays(weeknumber * 7).AddSeconds(seconds);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.