Based on pakores solution :
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); Date reference = dateFormat.parse("00:00:00"); Date date = dateFormat.parse(string); long seconds = (date.getTime() - reference.getTime()) / 1000L;
reference used to compensate for different time zones, and there is no problem with daylight saving time, because SimpleDateFormat does NOT use the actual date, it returns the Epoc date (January 1, 1970 = no DST).
Simplification (not much):
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = dateFormat.parse("01:00:10"); long seconds = date.getTime() / 1000L;
but I would still look at Joda-Time ...
source share