Zeit aus NMEA-Stream in SimpleDateFormat

  • Antworten:0
da st
  • Forum-Beiträge: 1

07.02.2012, 08:50:52 via Website

ich hätte da noch eine frage und zwar habe ich standardmäßig die GMT-Zeit in die Datenbank gespeichert:

1private final DateFormat timestampFormat = new SimpleDateFormat("yyyyMMddHHmmss");
2GregorianCalendar greg = new GregorianCalendar();
3 TimeZone tz = greg.getTimeZone();
4 int offset = tz.getOffset(System.currentTimeMillis());
5 greg.add(Calendar.SECOND, (offset/1000) * -1);;
6 StringBuffer queryBuf = new StringBuffer();
7 queryBuf.append("INSERT INTO "+POINTS_TABLE_NAME+
8 " (GMTTIMESTAMP,LATITUDE,LONGITUDE,ALTITUDE,ACCURACY,SPEED,BEARING) VALUES (" +
9 "'"+timestampFormat.format(greg.getTime())+"',"+
10 loc.getLatitude()+","+...
jetzt möchte ich aber die GPS-Zeit in die Datenbank hineinspeichern, die aus dem NMEA Stream herausgelesen wird:

1public void onNmeaReceived(long timestamp, String nmea) {
2
3 if (!nmea.startsWith(NMEA_RMC))
4 return ;
5 // extract time, date
6 String[] tokens = nmea.split(",");
7 String utcTime = tokens[1];
8 String utcDate = tokens[9];
9
10 // parse
11 DateFormat df = new SimpleDateFormat("HHmmss.S ddMMyy Z");
12 String GPSTime = utcTime + " " + utcDate + " +0000";

wie bringe ich die GPSTime, die nur aus 2 Strings besteht, in das SimpleDateFormat "timestampFormat" (damit auch beim SELECT ein ORDER BY GMTTIMESTAMP ASC möglich ist)?

Antworten