1
  public static void main(String[] args) throws ParseException {
        java.util.Date temp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS")
                .parse("2015-03-24 20:12:20.135000");
        System.out.println(temp);

For the same code when I use different seconds I am getting output as Tue Mar 24 20:14:35 CET 2015. I am getting everything correct except minutes and seconds. My tasks is to print the data in column which is 2015-03-24 01:55:23.999000 to round off the seconds and show it as 2015-03-24 01:55:24. Can you please tell me how it is possible or how to truncate

kiran kumar
  • 153
  • 4
  • 12
  • possible duplicate of [How to parse date string to Date?](http://stackoverflow.com/questions/4496359/how-to-parse-date-string-to-date) – JFPicard Apr 21 '15 at 16:27

1 Answers1

7

The S format character for SimpleDateFormat means milliseconds, not microseconds.

It's interpreting 135000 as 135,000 milliseconds, or 135 seconds. Then it adds 2 minutes and 15 seconds, yielding 20:14:35 instead of 20:12:20.135.

You'll need to truncate the string to read "2015-03-24 20:12:20.135" so 135 milliseconds is interpreted correctly.

rgettman
  • 176,041
  • 30
  • 275
  • 357
  • My tasks is to print the data in column which is 2015-03-24 01:55:23.999000 to round off the seconds and show it as 2015-03-24 01:55:24. Can you please tell me how it is possible or how to truncate? – kiran kumar Apr 21 '15 at 22:29