NMEA { static long parseTime(@Nullable String time) { if (time == null || time.isEmpty()) { return 0; } else { try { if (time.indexOf('.') != 6) { Log.e(TAG, "Time format error " + time); } final long hour = Integer.parseInt(time.substring(0, 2)); final long min = Integer.parseInt(time.substring(2, 4)); final long sec = Integer.parseInt(time.substring(4, 6)); final long ms = time.length() <= 6 ? 0 : (long) (1000 * Double.parseDouble(time.substring(6))); return hour * 3600000 + min * 60000 + sec * 1000 + ms; } catch (Exception e) { return 0; } } }    }
@Test public void parseTime() { assertEquals(72258990L, NMEA.parseTime("200418.99")); assertEquals(0L, NMEA.parseTime(null)); assertEquals(0L, NMEA.parseTime("")); assertEquals(0L, NMEA.parseTime("X")); }