I have a gps time in the database,and when I do some query,I have to use the java.util.Date,however I found that I do not know how to change the gps time to java.util.Date.
Here is a example:
The readable time === The GPS time
2010-11-15 13:10:00 === 6342541920开发者_如何学编程00000000
2010-11-15 14:10:00 === 634254228000000000
The period of the two date is "36000000000",,obviously it stands for one hour,so I think the unit of the gps time in the db must be nanosecond.
1 hour =3600 seconds= 3600*1000 milliseconds == 3600*1000*10000 nanoseconds
Then I try to convert the gps time:
Take the " 634254228000000000" as example,it stands for("2010-11-15 14:10:00");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
Date d = new Date(63425422800000L);
System.out.println(sdf.format(d));
The result is
3979-11-15 13:00:00+0000.
Of course it is wrong,then I try to calculate :
63425422800000/3600000/24/365=2011.xxx
So it seems that the gps time here is not calcuated from Epoch(1970-01-01 00:00:00+0000). It maybe something like (0001-01-01 00:00:00+0000).
Then I try to use the following method:
Date date_0=sdf.parse("0001-01-01 00:00:00+0000");
Date d = new Date(63425422800000L);
System.out.println(sdf.format(d.getTime() + date_0.getTime()));
The result is:
2010-11-13 13:00:00+0000. :(
Now I am confusing about how to calculate this gps time.
Any suggestion?
1 millisecond = 1 000 000 nanoseconds
so... 1 hour =3600 seconds= 3600*1000 milliseconds == 3600*1000*10000000 nanoseconds
Notice that GPS time is 15 seconds ahead from UTC : gps-time-representation-library
There are other time and date systems as well; for example, the time scale used by the satellite-based global positioning system (GPS) is synchronized to UTC but is not adjusted for leap seconds.
Quoted from : Java Util Date API
GPS time was zero at 6-Jan-1980
as opposed to Epoch which was zero at 1970-01-01 00:00:00+0000
Here is the simple Java code I used to convert GPS time (ms) to Java Date:
BigInteger gpsTime = new BigInteger("973865400000");
GregorianCalendar calendar =
new GregorianCalendar(1980, Calendar.JANUARY, 6, 0, 0, 0);
long gpsDiff = calendar.getTimeInMillis(); // gps offset to a
Date javaDate = new Date(gpsDiff + gpsTime.longValue());
System.out.println("Java Date: " + javaDate);
// prints: Java Date: Mon Nov 15 14:10:00 EST 2010
精彩评论