Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
632 views
in Technique[技术] by (71.8m points)

java - Not able to understand "YYYY-MM-DDTHH:MM:SS" date format

I am trying to parse following date time string

2018-01-30T23:59:59.000

I am not able to understand which standard format it is like UTC or ISO_8601

while parsing in the following manner:

SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD'T'HH:MM:SS:MS");
        Date date = null;
        try {
            date = sdf.parse("2018-01-30T23:59:59.000");
        } catch (ParseException e) {
            e.printStackTrace();
        }

But It is throwing following exception:

java.text.ParseException: Unparseable date: "2018-01-30T23:59:59.000"

Any help is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

See the doc of SimpleDateFormat and try this:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...