Q:

Parsing String to Date object changed value

To change the time format (from HH:mm:ss to HH:mm), I used the following snippet.  
Date dateObj = new SimpleDateFormat("HH:mm:ss").parse(time);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
String time = simpleDateFormat.format(dateObj);  

When I test with the correct time, it can change the format correctly.
But, when I test with wrong time, it change not only format but also time itself.
For example,

1:70:00 => 02:10 (after converting)
27:00:00 => 03:00 (after converting)  

I only would like to change the format instead of changing both format and value.
Is there any way to do so?

A:

When you parse a time string like "1:70", Java calculates the canonical time from that as "2:10".
Since you don't want such time recalculation, simply reformat with:

drop seconds
add padding zeros

It's better to use String operations. For example something like this:
    String str = "1:70:00";
    String[] parts = str.split(":");
    String newFormat = String.format("%02d:%02d", Integer.parseInt(parts[0]), Integer.parseInt(parts[1]));
    // will be: "01:70"

