TestingTest's answers your question already. Yet, if you want a different behaviour which does not re-calculate the minute you could use java.time.LocalDateTime
(you need Java 8 though). This class does not mess up the minutes like SimpleDateformat
.
See the difference in the code snippet below:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class TimeChecks {
public static void main(String[] args) throws ParseException {
String dddddd = "2017-11-29 09:24:03.857921";
SimpleDateFormat fullMonthFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");
SimpleDateFormat fullMonthFormat2 = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss.SSSSSS");
Date strd11;
strd11 = fullMonthFormat1.parse(dddddd);
System.out.println("chec date" + strd11);
String aa = fullMonthFormat2.format(strd11);
System.out.println("aa date" + aa);
LocalDateTime localDate = LocalDateTime.parse(dddddd, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"));
System.out.printf("Local date: %s%n", localDate);
}
}
This prints out:
chec dateWed Nov 29 09:38:20 GMT 2017
aa date29-Nov-2017 09:38:20.000921
Local date: 2017-11-29T09:24:03.857921
As you can see local date time does not change the minutes - it keeps the milliseconds as is.