aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
index 8b70d50..7c361a9 100644
--- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
+++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
@@ -22,6 +22,7 @@ package org.broeuschmeul.android.gps.nmea.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -527,16 +528,17 @@ public class NmeaParser {
}
public long parseNmeaTime(String time){
long timestamp = 0;
- SimpleDateFormat fmt = new SimpleDateFormat("HHmmss.S");
+ SimpleDateFormat fmt = new SimpleDateFormat("HHmmss.SSS");
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
try {
if (time != null && time != null){
long now = System.currentTimeMillis();
long today = now - (now %86400000L);
long temp1;
- temp1 = fmt.parse(time).getTime();
+ // sometime we don't have millisecond in the time string, so we have to reformat it
+ temp1 = fmt.parse(String.format((Locale)null,"%010.3f", Double.parseDouble(time))).getTime();
long temp2 = today+temp1;
- //
+ // if we're around midnight we could have a problem...
if (temp2 - now > 43200000L) {
timestamp = temp2 - 86400000L;
} else if (now - temp2 > 43200000L){