how to transfer a time which was zero at year of 0000(maybe) to java.util.Date
Posted
by
hguser
on Stack Overflow
See other posts from Stack Overflow
or by hguser
Published on 2011-03-19T05:37:51Z
Indexed on
2011/03/19
16:10 UTC
Read the original article
Hit count: 175
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 === 634254192000000000
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?
© Stack Overflow or respective owner