Result of parsing date is wrong by 16 hours 2 minu

2019-06-14 18:13发布

I have a string 07/Dec/2016:07:38:59 1000. I want to parse it to a date. What do I do to become a date 07/Dec/2016 07:38:59 1000 as a result? Now it prints out Wed Dec 07 23:40:59 CET 2016.

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeParse {
    public static void main(String[] args) throws ParseException {
        String time ="07/Dec/2016:07:38:59 1000";
        SimpleDateFormat format = new SimpleDateFormat("dd/MMM/yyyy:hh:mm:ss");

        String dateString = format.format( new Date()   );
        Date   date       = format.parse ( "07/Dec/2016:07:38:59 1000" );

        System.out.println(date);

    }
}

1条回答
叼着烟拽天下
2楼-- · 2019-06-14 18:58

I'm assuming the 1000 is supposed to be milliseconds? if so, it's incorrect. it's like writing 13:60:60

This also means the time string format you entered is missing the milliseconds value. It should be "dd/MMM/yyyy:hh:mm:ss SSS" milliseconds value should not be more than 3 digits

查看更多
登录 后发表回答