The different values you stated are caused by mixing up the 1970 to 1980 offset with leap seconds.
The correct offset value is 315964800 seconds.
Explanation:
UTC and GPS time deviate (on average) every 18 months by one additional second.
This is called a leap second, introduced in UTC time base, necessary to adjust for changes in the earth's rotation.
GPS Time not adjusted by leap seconds.
Currently (2013) there is an offset of 16s:
GPS Time-UTC = 16 seconds
Unix time is a time format not a time reference.
It represents the number of milliseconds (or seconds) since 1.1.1970 UTC.
Ideally your system time is synchronized with UTC by a TimeServer (NTP).
To convert, and get your offset, you should use a fixed offset: (6.1.1980 UTC - 1.1.1970 UTC)
and THEN add the current value of GPS to UTC deviation (currently 16s).
E.g make that value configurable, or read the current offset from a GPS device (they know the difference between UTC and GPS Time)
The different values you stated are caused by mixing up 1970 to 1980 offset with leap seconds.
Dont do that, handle them separately.
This java program:
SimpleDateFormat df = new SimpleDateFormat();
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date x = df.parse("1.1.1970 00:00:00");
Date y = df.parse("6.1.1980 00:00:00");
long diff = y.getTime() - x.getTime();
long diffSec = diff / 1000;
System.out.println("diffSec= " + diffSec);
Outputs this value:
diffSec= 315964800
So this is the correct offset between 1.1.1970 UTC and 6.1.1980 UTC where GPS Time began.
Then you have to correct further 16 seconds which were introduced since 6.1.1980 and today, to calculate the GPS Time of a current UTC time.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…