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
337 views
in Technique[技术] by (71.8m points)

android java parse date from string

In android application I'm trying to parse Date from string to find difference between two times.

SimpleDateFormat dateFormatDateAndTime = new SimpleDateFormat("ddMMyyyyHHMM");
Date startDateTime = dateFormatDateAndTime.parse("060420150134");
Log.v(TAG, "startDateTime: " + startDateTime);  //Fri Oct 06 01:00:00 GMT+05:30 2017   

So, I have to parse 060420150134 so that I get 06 Apr 2015 01:34 and for that my format is ddMMyyyyHHMM

But I get here Fri Oct 06 01:00:00 GMT+05:30 2017

So i'm doing what's wrong? How to parse here?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

You need to change the second MM (months) to mm (minutes):

SimpleDateFormat dateFormatDateAndTime = new SimpleDateFormat("ddMMyyyyHHmm");

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

...